Search in sources :

Example 1 with XLIFFFilter

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);
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) URISyntaxException(java.net.URISyntaxException) StatCount(org.omegat.core.statistics.StatCount) PatternConsts(org.omegat.util.PatternConsts) StaticUtils(org.omegat.util.StaticUtils) TranslationException(org.omegat.filters2.TranslationException) Core(org.omegat.core.Core) Assert.fail(org.junit.Assert.fail) XLIFFFilter(org.omegat.filters3.xml.xliff.XLIFFFilter) Before(org.junit.Before) IProject(org.omegat.core.data.IProject) ITranslateCallback(org.omegat.filters2.ITranslateCallback) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) XLIFFOptions(org.omegat.filters3.xml.xliff.XLIFFOptions) Collectors(java.util.stream.Collectors) File(java.io.File) StatisticsSettings(org.omegat.core.statistics.StatisticsSettings) List(java.util.List) XLIFFDialect(org.omegat.filters3.xml.xliff.XLIFFDialect) TreeMap(java.util.TreeMap) Assert.assertFalse(org.junit.Assert.assertFalse) SAXException(org.xml.sax.SAXException) Preferences(org.omegat.util.Preferences) Assert.assertEquals(org.junit.Assert.assertEquals) ITranslateCallback(org.omegat.filters2.ITranslateCallback) SourceTextEntry(org.omegat.core.data.SourceTextEntry) File(java.io.File) IProject(org.omegat.core.data.IProject) Test(org.junit.Test)

Example 2 with XLIFFFilter

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>()));
}
Also used : XLIFFOptions(org.omegat.filters3.xml.xliff.XLIFFOptions) XLIFFDialect(org.omegat.filters3.xml.xliff.XLIFFDialect) TreeMap(java.util.TreeMap) XLIFFFilter(org.omegat.filters3.xml.xliff.XLIFFFilter) Before(org.junit.Before)

Aggregations

TreeMap (java.util.TreeMap)2 Before (org.junit.Before)2 XLIFFDialect (org.omegat.filters3.xml.xliff.XLIFFDialect)2 XLIFFFilter (org.omegat.filters3.xml.xliff.XLIFFFilter)2 XLIFFOptions (org.omegat.filters3.xml.xliff.XLIFFOptions)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 FileUtils (org.apache.commons.io.FileUtils)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1 Core (org.omegat.core.Core)1 IProject (org.omegat.core.data.IProject)1 SourceTextEntry (org.omegat.core.data.SourceTextEntry)1 StatCount (org.omegat.core.statistics.StatCount)1