use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class XHTMLFilterTest method testParse.
@Test
public void testParse() throws Exception {
String f = "test/data/filters/xhtml/file-XHTMLFilter.html";
XHTMLFilter filter = new XHTMLFilter();
filter.isFileSupported(new File(f), new TreeMap<String, String>(), new FilterContext(new Language("en"), new Language("be"), false));
parse(filter, f);
}
use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class TmxComplianceBase method loadTexts.
protected List<String> loadTexts(final IFilter filter, final File sourceFile, final String inCharset, final FilterContext context, final Map<String, String> config) throws Exception {
final List<String> result = new ArrayList<String>();
IParseCallback callback = new IParseCallback() {
public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, IFilter filter) {
}
public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, String path, IFilter filter, List<ProtectedPart> protectedParts) {
String[] props = comment == null ? null : new String[] { SegmentProperties.COMMENT, comment };
addEntryWithProperties(id, source, translation, isFuzzy, props, path, filter, protectedParts);
}
@Override
public void addEntryWithProperties(String id, String source, String translation, boolean isFuzzy, String[] props, String path, IFilter filter, List<ProtectedPart> protectedParts) {
result.addAll(Core.getSegmenter().segment(context.getSourceLang(), source, null, null));
}
public void linkPrevNextSegments() {
}
};
filter.parseFile(sourceFile, config, context, callback);
return result;
}
use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class TmxComplianceBase method align.
protected void align(IFilter filter, File sourceFile, String inCharset, File translatedFile, String outCharset, ProjectProperties props) throws Exception {
FilterContext fc = new FilterContext(props);
fc.setInEncoding(inCharset);
fc.setOutEncoding(outCharset);
RealProject.AlignFilesCallback callback = new RealProject.AlignFilesCallback(props);
filter.alignFile(sourceFile, translatedFile, null, fc, callback);
ProjectTMX tmx = new ProjectTMX(props.getSourceLanguage(), props.getTargetLanguage(), props.isSentenceSegmentingEnabled(), outFile, orphanedCallback);
for (Map.Entry<String, TMXEntry> en : callback.data.entrySet()) {
tmx.defaults.put(en.getKey(), en.getValue());
}
tmx.exportTMX(props, outFile, false, false, true);
}
use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class TmxComplianceTests method testExport1B.
/**
* Test Export1B - HTML
*/
@Test
public void testExport1B() throws Exception {
File tmxFile = new File("test/data/tmx/TMXComplianceKit/ExportTest1B.tmx");
File sourceFile = new File("test/data/tmx/TMXComplianceKit/ExportTest1B.htm");
File translatedFile = new File("test/data/tmx/TMXComplianceKit/ExportTest1B_fr.htm");
ProjectProperties props = new TestProjectProperties("EN-US", "FR-CA");
FilterContext fc = new FilterContext(props);
fc.setInEncoding("windows-1252");
Map<String, String> config = new TreeMap<String, String>();
new HTMLOptions(config).setSkipMeta("content=en-us,content=fr-ca");
List<String> sources = loadTexts(new HTMLFilter2(), sourceFile, null, fc, config);
List<String> translations = loadTexts(new HTMLFilter2(), translatedFile, null, fc, config);
assertEquals(sources.size(), translations.size());
ProjectTMX tmx = new ProjectTMX(props.getSourceLanguage(), props.getTargetLanguage(), props.isSentenceSegmentingEnabled(), outFile, orphanedCallback);
for (int i = 0; i < sources.size(); i++) {
tmx.defaults.put(sources.get(i), createTMXEntry(sources.get(i), translations.get(i), true));
}
tmx.exportTMX(props, outFile, false, false, true);
compareTMX(tmxFile, outFile, 2);
}
use of org.omegat.filters2.FilterContext in project omegat by omegat-org.
the class HTMLFilter2Test method testTagsOptimization.
@Test
public void testTagsOptimization() throws Exception {
String f = "test/data/filters/html/file-HTMLFilter2-tags-optimization.html";
HTMLFilter2 filter = new HTMLFilter2();
Core.getFilterMaster().getConfig().setRemoveTags(false);
filter.isFileSupported(new File(f), Collections.emptyMap(), new FilterContext(new Language("en"), new Language("be"), false));
IProject.FileInfo fi = loadSourceFiles(filter, f);
checkMultiStart(fi, f);
checkMultiNoPrevNext("<i0/><b1><c2>This</c2> is <i3>first</i3> line.</b1>", null, null, null);
translateXML(filter, f);
Core.getFilterMaster().getConfig().setRemoveTags(true);
filter.isFileSupported(new File(f), Collections.emptyMap(), new FilterContext(new Language("en"), new Language("be"), false));
fi = loadSourceFiles(filter, f);
checkMultiStart(fi, f);
checkMultiNoPrevNext("<c0>This</c0> is <i1>first</i1> line.", null, null, null);
translateXML(filter, f);
}
Aggregations