Search in sources :

Example 21 with Language

use of org.omegat.util.Language in project omegat by omegat-org.

the class HunspellTokenizer method langsToStrings.

private static String[] langsToStrings(Set<Language> langs) {
    List<String> result = new ArrayList<String>(langs.size() * 2);
    for (Language lang : langs) {
        result.add(lang.getLanguage().toLowerCase(Locale.ENGLISH));
        result.add(lang.getLanguageCode().toLowerCase(Locale.ENGLISH));
    }
    return result.toArray(new String[result.size()]);
}
Also used : Language(org.omegat.util.Language) ArrayList(java.util.ArrayList)

Example 22 with Language

use of org.omegat.util.Language in project omegat by omegat-org.

the class ExternalTMFactoryTest method setUp.

@Before
public final void setUp() {
    Core.setSegmenter(new Segmenter(SRX.getDefault()));
    FilterMaster.setFilterClasses(Arrays.asList(PoFilter.class, MozillaLangFilter.class));
    Core.setFilterMaster(new FilterMaster(FilterMaster.createDefaultFiltersConfig()));
    ProjectProperties props = new ProjectProperties() {

        public Language getSourceLanguage() {
            return new Language("en");
        }

        public Language getTargetLanguage() {
            return new Language("pl");
        }

        @Override
        public boolean isSentenceSegmentingEnabled() {
            return true;
        }
    };
    Core.setProject(new NotLoadedProject() {

        @Override
        public ProjectProperties getProjectProperties() {
            return props;
        }
    });
}
Also used : Language(org.omegat.util.Language) FilterMaster(org.omegat.filters2.master.FilterMaster) PoFilter(org.omegat.filters2.po.PoFilter) MozillaLangFilter(org.omegat.filters2.mozlang.MozillaLangFilter) Segmenter(org.omegat.core.segmentation.Segmenter) Before(org.junit.Before)

Example 23 with Language

use of org.omegat.util.Language in project omegat by omegat-org.

the class TmxSegmentationTest method testProjectTMX.

@Test
public void testProjectTMX() throws Exception {
    ProjectProperties props = new ProjectProperties();
    props.setSupportDefaultTranslations(true);
    props.setSourceLanguage(new Language("en"));
    props.setTargetLanguage(new Language("fr"));
    props.setSentenceSegmentingEnabled(true);
    ProjectTMX tmx = new ProjectTMX(props.getSourceLanguage(), props.getTargetLanguage(), props.isSentenceSegmentingEnabled(), new File("test/data/tmx/resegmenting.tmx"), new ProjectTMX.CheckOrphanedCallback() {

        public boolean existSourceInProject(String src) {
            return true;
        }

        public boolean existEntryInProject(EntryKey key) {
            return true;
        }
    });
    assertEquals(2, tmx.defaults.size());
    assertEquals("Ceci est un test.", tmx.defaults.get("This is test.").translation);
    assertEquals("Juste un test.", tmx.defaults.get("Just a test.").translation);
}
Also used : Language(org.omegat.util.Language) File(java.io.File) Test(org.junit.Test)

Example 24 with Language

use of org.omegat.util.Language in project omegat by omegat-org.

the class TmxSegmentationTest method testExternalTMX.

@Test
public void testExternalTMX() throws Exception {
    ExternalTMX tmx = new ExternalTMFactory.TMXLoader(new File("test/data/tmx/resegmenting.tmx")).setDoSegmenting(true).load(new Language("en"), new Language("fr"));
    assertEquals(2, tmx.getEntries().size());
    assertEquals("This is test.", tmx.getEntries().get(0).source);
    assertEquals("Ceci est un test.", tmx.getEntries().get(0).translation);
    assertEquals("Just a test.", tmx.getEntries().get(1).source);
    assertEquals("Juste un test.", tmx.getEntries().get(1).translation);
}
Also used : Language(org.omegat.util.Language) File(java.io.File) Test(org.junit.Test)

Example 25 with Language

use of org.omegat.util.Language in project omegat by omegat-org.

the class DictionaryDataTest method testLookup.

@Test
public void testLookup() {
    DictionaryData<String> data = new DictionaryData<>(new Language(Locale.ENGLISH));
    data.add("foobar", "bazbiz");
    data.add("foobar", "buzzfizz");
    data.add("ho\u0308ge", "hogehoge");
    data.add("blah", "blooh");
    data.add("BLAH", "blooh2");
    // Test pre-finalized state
    assertEquals(-1, data.size());
    try {
        data.lookUp("foobar");
        fail();
    } catch (IllegalStateException ex) {
    // Not finalized yet
    }
    try {
        data.lookUpPredictive("foobar");
        fail();
    } catch (IllegalStateException ex) {
    // Not finalized yet
    }
    data.done();
    assertEquals(4, data.size());
    // Test normal lookup
    List<Entry<String, String>> result = data.lookUp("foobar");
    assertEquals(2, result.size());
    assertEquals("bazbiz", result.get(0).getValue());
    assertEquals("buzzfizz", result.get(1).getValue());
    List<Entry<String, String>> presult = data.lookUpPredictive("foobar");
    assertEquals(2, result.size());
    assertEquals("bazbiz", presult.get(0).getValue());
    assertEquals("buzzfizz", presult.get(1).getValue());
    // Test case matching
    result = data.lookUp("FOOBAR");
    assertEquals(2, result.size());
    assertEquals("bazbiz", result.get(0).getValue());
    assertEquals("foobar", result.get(0).getKey());
    assertEquals("buzzfizz", result.get(1).getValue());
    assertEquals("foobar", result.get(1).getKey());
    // Test case differentiation
    result = data.lookUp("blah");
    assertEquals(2, result.size());
    assertEquals("blooh", result.get(0).getValue());
    assertEquals("blah", result.get(0).getKey());
    assertEquals("blooh2", result.get(1).getValue());
    assertEquals("blah", result.get(1).getKey());
    result = data.lookUp("BLAH");
    assertEquals(1, result.size());
    assertEquals("blooh2", result.get(0).getValue());
    assertEquals("BLAH", result.get(0).getKey());
    // Test prediction
    presult = data.lookUpPredictive("foo");
    assertEquals(2, presult.size());
    assertEquals("bazbiz", presult.get(0).getValue());
    assertEquals("foobar", presult.get(0).getKey());
    assertEquals("buzzfizz", presult.get(1).getValue());
    assertEquals("foobar", presult.get(1).getKey());
    result = data.lookUp("foo");
    assertTrue(result.isEmpty());
    // Test Unicode normalization
    result = data.lookUp("h\u00f6ge");
    assertEquals(1, result.size());
    assertEquals("hogehoge", result.get(0).getValue());
    // Test non-existent key
    result = data.lookUp("zzzz");
    assertTrue(result.isEmpty());
}
Also used : Entry(java.util.Map.Entry) Language(org.omegat.util.Language) Test(org.junit.Test)

Aggregations

Language (org.omegat.util.Language)43 Test (org.junit.Test)16 File (java.io.File)13 ArrayList (java.util.ArrayList)13 Map (java.util.Map)7 FilterContext (org.omegat.filters2.FilterContext)7 List (java.util.List)6 IProject (org.omegat.core.data.IProject)6 SourceTextEntry (org.omegat.core.data.SourceTextEntry)5 HashMap (java.util.HashMap)4 Before (org.junit.Before)4 EntryKey (org.omegat.core.data.EntryKey)4 ProjectTMX (org.omegat.core.data.ProjectTMX)4 TMXEntry (org.omegat.core.data.TMXEntry)4 XHTMLFilter (org.omegat.filters3.xml.xhtml.XHTMLFilter)4 DefaultTokenizer (org.omegat.tokenizer.DefaultTokenizer)4 ITokenizer (org.omegat.tokenizer.ITokenizer)4 IOException (java.io.IOException)3 Files (java.nio.file.Files)3 Matcher (java.util.regex.Matcher)3