Search in sources :

Example 1 with HTMLFilter2

use of org.omegat.filters2.html2.HTMLFilter2 in project omegat by omegat-org.

the class TmxComplianceTests method testExport2A.

/**
 * Test Export2A - HTML
 */
@Test
public void testExport2A() throws Exception {
    File tmxFile = new File("test/data/tmx/TMXComplianceKit/ExportTest2A.tmx");
    File sourceFile = new File("test/data/tmx/TMXComplianceKit/ExportTest2A.htm");
    File translatedFile = new File("test/data/tmx/TMXComplianceKit/ExportTest2A_fr.htm");
    ProjectProperties props = new TestProjectProperties("EN-US", "FR-CA");
    props.setSentenceSegmentingEnabled(true);
    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, true, true);
    compareTMX(tmxFile, outFile, 12);
}
Also used : HTMLOptions(org.omegat.filters2.html2.HTMLOptions) TreeMap(java.util.TreeMap) HTMLFilter2(org.omegat.filters2.html2.HTMLFilter2) File(java.io.File) FilterContext(org.omegat.filters2.FilterContext) Test(org.junit.Test)

Example 2 with HTMLFilter2

use of org.omegat.filters2.html2.HTMLFilter2 in project omegat by omegat-org.

the class TmxComplianceTests method testImport2A.

/**
 * Test Import2A - Content Markup Syntax in HTML.
 *
 * TEST CHANGED FROM TMX COMPLIANCE PACK BECAUSE WE HAVE OTHER SEGMENTATION SETTINGS, i.e. "Picture: <img
 * src="img.png"/>" should be processed as one segment by TMX compliance tests, but it's not a one segment
 * by OmegaT segmentation. Since it out of scope of testing, we patch tmx for runtime-only.
 */
@Test
public void testImport2A() throws Exception {
    ProjectProperties props = new TestProjectProperties("EN-US", "FR-CA");
    props.setSentenceSegmentingEnabled(true);
    Map<String, String> config = new TreeMap<String, String>();
    config.put(HTMLOptions.OPTION_TRANSLATE_SRC, "false");
    config.put(HTMLOptions.OPTION_SKIP_META, "true");
    Map<String, TMXEntry> fix = new TreeMap<String, TMXEntry>();
    fix.put("Picture:", createTMXEntry("Picture:", "Image:", true));
    translateUsingTmx(new HTMLFilter2(), config, "ImportTest2A.htm", "UTF-8", "ImportTest2A.tmx", "windows-1252", props, fix);
    List<String> lines1 = readTextFile(new File("test/data/tmx/TMXComplianceKit/ImportTest2A_fr-ca.htm"), "windows-1252");
    List<String> lines2 = readTextFile(outFile, "windows-1252");
    // fix meta line, since OmegaT writes own meta line for encoding
    lines2.set(2, "<meta content=\"text/html; charset=windows-1252\" http-equiv=\"Content-Type\">");
    assertEquals(lines1.size(), lines2.size());
    for (int i = 0; i < lines1.size(); i++) {
        // HTML spec allows unescaped U+0022 QUOTE MARK (outside of attribute values);
        // we produce unescaped but the test assumes escaped, so we normalize for comparison purposes.
        String line1 = normalize(lines1.get(i));
        String line2 = normalize(lines2.get(i));
        assertEquals(line1, line2);
    }
}
Also used : TreeMap(java.util.TreeMap) HTMLFilter2(org.omegat.filters2.html2.HTMLFilter2) File(java.io.File) Test(org.junit.Test)

Example 3 with HTMLFilter2

use of org.omegat.filters2.html2.HTMLFilter2 in project omegat by omegat-org.

the class HTMLFilter2Test method testParse.

@Test
public void testParse() throws Exception {
    List<String> entries = parse(new HTMLFilter2(), "test/data/filters/html/file-HTMLFilter2.html");
    assertEquals(entries.size(), 2);
    assertEquals("This is first line.", entries.get(0));
    assertEquals("This is second line.", entries.get(1));
}
Also used : HTMLFilter2(org.omegat.filters2.html2.HTMLFilter2) Test(org.junit.Test)

Example 4 with HTMLFilter2

use of org.omegat.filters2.html2.HTMLFilter2 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);
}
Also used : HTMLOptions(org.omegat.filters2.html2.HTMLOptions) TreeMap(java.util.TreeMap) HTMLFilter2(org.omegat.filters2.html2.HTMLFilter2) File(java.io.File) FilterContext(org.omegat.filters2.FilterContext) Test(org.junit.Test)

Example 5 with HTMLFilter2

use of org.omegat.filters2.html2.HTMLFilter2 in project omegat by omegat-org.

the class HTMLFilter2Test method testLoad.

@Test
public void testLoad() throws Exception {
    String f = "test/data/filters/html/file-HTMLFilter2.html";
    HTMLFilter2 filter = new HTMLFilter2();
    IProject.FileInfo fi = loadSourceFiles(filter, f);
    checkMultiStart(fi, f);
    checkMulti("This is first line.", null, null, "", "This is second line.", null);
    checkMulti("This is second line.", null, null, "This is first line.", "", null);
    checkMultiEnd();
    f = "test/data/filters/html/file-HTMLFilter2-SMP.html";
    fi = loadSourceFiles(filter, f);
    checkMultiStart(fi, f);
    checkMulti("\uD835\uDC00\uD835\uDC01\uD835\uDC02", null, null, "", "\uD835\uDC03\uD835\uDC04\uD835\uDC05", null);
    checkMulti("\uD835\uDC03\uD835\uDC04\uD835\uDC05", null, null, "\uD835\uDC00\uD835\uDC01\uD835\uDC02", "", null);
    checkMultiEnd();
}
Also used : HTMLFilter2(org.omegat.filters2.html2.HTMLFilter2) IProject(org.omegat.core.data.IProject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 HTMLFilter2 (org.omegat.filters2.html2.HTMLFilter2)7 File (java.io.File)4 TreeMap (java.util.TreeMap)3 FilterContext (org.omegat.filters2.FilterContext)3 IProject (org.omegat.core.data.IProject)2 HTMLOptions (org.omegat.filters2.html2.HTMLOptions)2 Language (org.omegat.util.Language)1