Search in sources :

Example 16 with IFilter

use of org.omegat.filters2.IFilter 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 17 with IFilter

use of org.omegat.filters2.IFilter in project omegat by omegat-org.

the class ILIASFilterTest method testAlign.

@Test
public void testAlign() throws Exception {
    final AlignResultHolder alignResult = new AlignResultHolder();
    align(new ILIASFilter(), "ilias/ILIASFilterAlign.lang", "ilias/ILIASFilterAlign-tr.lang", new IAlignCallback() {

        @Override
        public void addTranslation(String id, String source, String translation, boolean isFuzzy, String comment, IFilter filter) {
            alignResult.aligned = id.equals("module_name#:#variable_name") && source.equals("original") && translation.equals("translated");
        }
    });
    assertTrue(alignResult.aligned);
}
Also used : IFilter(org.omegat.filters2.IFilter) ILIASFilter(org.omegat.filters2.text.ilias.ILIASFilter) IAlignCallback(org.omegat.filters2.IAlignCallback) Test(org.junit.Test)

Example 18 with IFilter

use of org.omegat.filters2.IFilter in project omegat by omegat-org.

the class TestFilterBase method parse.

/**
 * Helper function for testing the parseFile method of a given filter without options;
 * returns a list of source segments that the
 * filter-under-test finds in the given file and returns to the IParseCallback.addEntry method.
 * NB: Id, comments, fuzzyness, path, properties etc is all ignored.
 *
 * @param filter the filter to test
 * @param filename the file to use as input for the filter
 * @return list of source segments
 * @throws Exception when the filter throws an exception on parseFile.
 */
protected List<String> parse(AbstractFilter filter, String filename) throws Exception {
    final List<String> result = new ArrayList<String>();
    filter.parseFile(new File(filename), Collections.emptyMap(), context, new IParseCallback() {

        public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, IFilter filter) {
            addEntry(id, source, translation, isFuzzy, comment, null, filter, null);
        }

        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);
        }

        public void addEntryWithProperties(String id, String source, String translation, boolean isFuzzy, String[] props, String path, IFilter filter, List<ProtectedPart> protectedParts) {
            if (!source.isEmpty()) {
                result.add(source);
            }
        }

        public void linkPrevNextSegments() {
        }
    });
    return result;
}
Also used : IParseCallback(org.omegat.filters2.IParseCallback) ProtectedPart(org.omegat.core.data.ProtectedPart) IFilter(org.omegat.filters2.IFilter) ArrayList(java.util.ArrayList) File(java.io.File)

Example 19 with IFilter

use of org.omegat.filters2.IFilter in project omegat by omegat-org.

the class TestFilterBase method parse3.

/**
 * Helper function for testing the parseFile method of a given filter using some options;
 * returns a list of ParsedEntry with the
 * attributes that the filter-under-test finds in the given file and returns to the IParseCallback.addEntry method.
 * @param filter the filter to test
 * @param filename the file to use as input for the filter
 * @param options the filter options/config to use
 * @return list of found information
 * @throws Exception when the filter throws an exception on parseFile.
 */
protected List<ParsedEntry> parse3(AbstractFilter filter, String filename, Map<String, String> options) throws Exception {
    final List<ParsedEntry> result = new ArrayList<>();
    filter.parseFile(new File(filename), options, context, new IParseCallback() {

        public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, IFilter filter) {
            addEntry(id, source, translation, isFuzzy, comment, null, filter, null);
        }

        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) {
            if (source.isEmpty()) {
                return;
            }
            ParsedEntry e = new ParsedEntry();
            e.id = id;
            e.source = source;
            e.translation = translation;
            e.isFuzzy = isFuzzy;
            e.props = props;
            e.path = path;
            result.add(e);
        }

        public void linkPrevNextSegments() {
        }
    });
    return result;
}
Also used : IParseCallback(org.omegat.filters2.IParseCallback) ProtectedPart(org.omegat.core.data.ProtectedPart) IFilter(org.omegat.filters2.IFilter) ArrayList(java.util.ArrayList) File(java.io.File)

Example 20 with IFilter

use of org.omegat.filters2.IFilter in project omegat by omegat-org.

the class TestFilterBase method parse.

/**
 * Helper function for testing the parseFile method of a given filter using some options;
 * returns a list of source segments that
 * the filter-under-test finds in the given file and returns to the IParseCallback.addEntry method.
 * NB: Id, comments, fuzzyness, path, properties etc is all ignored.
 *
 * @param filter the filter to test
 * @param filename the file to use as input for the filter
 * @param options the filter options/config to use
 * @return list of source segments
 * @throws Exception when the filter throws an exception on parseFile.
 */
protected List<String> parse(AbstractFilter filter, String filename, Map<String, String> options) throws Exception {
    final List<String> result = new ArrayList<String>();
    filter.parseFile(new File(filename), options, context, new IParseCallback() {

        public void addEntry(String id, String source, String translation, boolean isFuzzy, String comment, IFilter filter) {
            addEntry(id, source, translation, isFuzzy, comment, null, filter, null);
        }

        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);
        }

        public void addEntryWithProperties(String id, String source, String translation, boolean isFuzzy, String[] props, String path, IFilter filter, List<ProtectedPart> protectedParts) {
            if (!source.isEmpty()) {
                result.add(source);
            }
        }

        public void linkPrevNextSegments() {
        }
    });
    return result;
}
Also used : IParseCallback(org.omegat.filters2.IParseCallback) ProtectedPart(org.omegat.core.data.ProtectedPart) IFilter(org.omegat.filters2.IFilter) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

IFilter (org.omegat.filters2.IFilter)19 File (java.io.File)8 Files (gen.core.filters.Files)5 ArrayList (java.util.ArrayList)5 FilterContext (org.omegat.filters2.FilterContext)5 IParseCallback (org.omegat.filters2.IParseCallback)5 Filter (gen.core.filters.Filter)4 Test (org.junit.Test)4 ProtectedPart (org.omegat.core.data.ProtectedPart)4 IAlignCallback (org.omegat.filters2.IAlignCallback)4 IOException (java.io.IOException)3 AbstractFilter (org.omegat.filters2.AbstractFilter)3 TranslationException (org.omegat.filters2.TranslationException)3 OneFilterTableModel (org.omegat.filters2.master.OneFilterTableModel)2 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 RandomAccessFile (java.io.RandomAccessFile)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1