use of org.omegat.filters3.xml.xliff.XLIFFFilter in project omegat by omegat-org.
the class XLIFFFilterTest method testTags.
@Test
public void testTags() throws Exception {
String f = "test/data/filters/xliff/file-XLIFFFilter-tags.xlf";
IProject.FileInfo fi = loadSourceFiles(filter, f);
SourceTextEntry ste;
checkMultiStart(fi, f);
// #1988732
checkMultiNoPrevNext("Link to <m0>http://localhost</m0>.", null, null, null);
// #1988732
checkMultiNoPrevNext("About <b0>Gandalf</b0>", null, null, "7");
checkMultiNoPrevNext("<i0>Tags</i0> translation zz<i1>2</i1>z <b2>-NONTRANSLATED", null, null, null);
checkMultiNoPrevNext("one <a0> two </b1> three <c2> four </d3> five", null, null, null);
ste = checkMultiNoPrevNext("About <m0>Gandalf</m0> and <m1>other</m1>.", null, null, null);
assertEquals(3, ste.getProtectedParts().length);
assertEquals("<m0>Gandalf</m0>", ste.getProtectedParts()[0].getTextInSourceSegment());
assertEquals("<mrk mtype=\"protected\">Gandalf</mrk>", ste.getProtectedParts()[0].getDetailsFromSourceFile());
assertEquals("Gandalf", ste.getProtectedParts()[0].getReplacementMatchCalculation());
assertEquals("<m1>", ste.getProtectedParts()[1].getTextInSourceSegment());
assertEquals("<mrk mtype=\"other\">", ste.getProtectedParts()[1].getDetailsFromSourceFile());
assertEquals(StaticUtils.TAG_REPLACEMENT, ste.getProtectedParts()[1].getReplacementMatchCalculation());
assertEquals("</m1>", ste.getProtectedParts()[2].getTextInSourceSegment());
assertEquals("</mrk>", ste.getProtectedParts()[2].getDetailsFromSourceFile());
assertEquals(StaticUtils.TAG_REPLACEMENT, ste.getProtectedParts()[2].getReplacementMatchCalculation());
checkMultiNoPrevNext("one <o0>two</o0> three", null, null, null);
checkMultiNoPrevNext("one <t0/> three", null, null, null);
checkMultiNoPrevNext("one <w0/> three", null, null, null);
checkMultiNoPrevNext("Nested tags: before <g0><g1><x2/></g1></g0> after", null, null, null);
checkMultiNoPrevNext("<m0>Check protected-only tag reading</m0>", null, null, null);
checkMultiEnd();
File inFile = new File("test/data/filters/xliff/file-XLIFFFilter-tags.xlf");
filter.translateFile(inFile, outFile, new TreeMap<String, String>(), context, new ITranslateCallback() {
public String getTranslation(String id, String source, String path) {
return source.replace("NONTRANSLATED", "TRANSLATED");
}
public String getTranslation(String id, String source) {
return source.replace("NONTRANSLATED", "TRANSLATED");
}
public void linkPrevNextSegments() {
}
public void setPass(int pass) {
}
});
File trFile = new File(outFile.getPath() + "-translated");
List<String> lines = Files.lines(inFile.toPath()).map(line -> line.replace("NONTRANSLATED", "TRANSLATED")).collect(Collectors.toList());
Files.write(trFile.toPath(), lines);
compareXML(trFile, outFile);
}
use of org.omegat.filters3.xml.xliff.XLIFFFilter in project omegat by omegat-org.
the class XLIFFFilterTest method setUp.
@Before
public final void setUp() {
filter = new XLIFFFilter();
XLIFFDialect dialect = (XLIFFDialect) filter.getDialect();
dialect.defineDialect(new XLIFFOptions(new TreeMap<String, String>()));
}
Aggregations