Search in sources :

Example 16 with FilterContext

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);
}
Also used : XHTMLFilter(org.omegat.filters3.xml.xhtml.XHTMLFilter) Language(org.omegat.util.Language) File(java.io.File) FilterContext(org.omegat.filters2.FilterContext) Test(org.junit.Test)

Example 17 with FilterContext

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;
}
Also used : IParseCallback(org.omegat.filters2.IParseCallback) IFilter(org.omegat.filters2.IFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with FilterContext

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);
}
Also used : Map(java.util.Map) TreeMap(java.util.TreeMap) FilterContext(org.omegat.filters2.FilterContext)

Example 19 with FilterContext

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);
}
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 20 with FilterContext

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);
}
Also used : Language(org.omegat.util.Language) HTMLFilter2(org.omegat.filters2.html2.HTMLFilter2) File(java.io.File) IProject(org.omegat.core.data.IProject) FilterContext(org.omegat.filters2.FilterContext) Test(org.junit.Test)

Aggregations

File (java.io.File)16 FilterContext (org.omegat.filters2.FilterContext)16 IFilter (org.omegat.filters2.IFilter)8 IOException (java.io.IOException)7 Test (org.junit.Test)7 TranslationException (org.omegat.filters2.TranslationException)7 Language (org.omegat.util.Language)5 FilterMaster (org.omegat.filters2.master.FilterMaster)4 XHTMLFilter (org.omegat.filters3.xml.xhtml.XHTMLFilter)4 RandomAccessFile (java.io.RandomAccessFile)3 TreeMap (java.util.TreeMap)3 IProject (org.omegat.core.data.IProject)3 HTMLFilter2 (org.omegat.filters2.html2.HTMLFilter2)3 Files (gen.core.filters.Files)2 Filter (gen.core.filters.Filter)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 ZipOutputStream (java.util.zip.ZipOutputStream)2