Search in sources :

Example 6 with Language

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

the class BrowseTaasCollectionsController method show.

public static void show() {
    dialog = new BrowseTaasCollectionsUI(Core.getMainWindow().getApplicationFrame(), true);
    final Language sourceLang = Core.getProject().getProjectProperties().getSourceLanguage();
    final Language targetLang = Core.getProject().getProjectProperties().getTargetLanguage();
    List<TaasCollection> list = Collections.emptyList();
    CollectionsTable model = new CollectionsTable(list, sourceLang, targetLang);
    dialog.tableCollections.setModel(model);
    dialog.tableCollections.setColumnModel(createColumnModel());
    dialog.labelStatus.setText(OStrings.getString("TAAS_STATUS_LIST"));
    new SwingWorker<List<TaasCollection>, Void>() {

        @Override
        protected List<TaasCollection> doInBackground() throws Exception {
            return TaaSPlugin.getClient().getCollectionsList();
        }

        @Override
        protected void done() {
            try {
                List<TaasCollection> list = get();
                removeUnusedCollections(list);
                CollectionsTable model = new CollectionsTable(list, sourceLang, targetLang);
                dialog.tableCollections.setModel(model);
                TableRowSorter<CollectionsTable> sorter = new TableRowSorter<CollectionsTable>(model);
                dialog.tableCollections.setRowSorter(sorter);
                sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
                dialog.tableCollections.setColumnModel(createColumnModel());
                dialog.labelStatus.setText(" ");
            } catch (ExecutionException e) {
                Throwable ex = e.getCause();
                if (ex instanceof TaaSClient.FormatError) {
                    Log.logErrorRB(ex, "TAAS_FORMAT_ERROR", ex.getMessage());
                    dialog.labelStatus.setText(OStrings.getString("TAAS_FORMAT_ERROR"));
                } else if (ex instanceof TaaSClient.Unauthorized) {
                    Log.logErrorRB(ex, "TAAS_UNAUTHORIZED_ERROR");
                    dialog.labelStatus.setText(OStrings.getString("TAAS_UNAUTHORIZED_ERROR"));
                } else {
                    Log.logErrorRB(ex, "TAAS_GENERAL_ERROR", ex.getMessage());
                    dialog.labelStatus.setText(MessageFormat.format(OStrings.getString("TAAS_GENERAL_ERROR"), ex.getMessage()));
                }
            } catch (InterruptedException ex) {
            }
        }
    }.execute();
    dialog.btnDownload.addActionListener(DOWNLOAD_LISTENER);
    StaticUIUtils.setEscapeClosable(dialog);
    dialog.btnClose.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    dialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
    dialog.setVisible(true);
}
Also used : TaasCollection(gen.taas.TaasCollection) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ActionEvent(java.awt.event.ActionEvent) ExecutionException(java.util.concurrent.ExecutionException) TaasLanguage(gen.taas.TaasLanguage) Language(org.omegat.util.Language) ActionListener(java.awt.event.ActionListener) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) TableRowSorter(javax.swing.table.TableRowSorter)

Example 7 with Language

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

the class BrowseTaasCollectionsController method removeUnusedCollections.

/**
 * Removes collections with zero terms count.
 */
static void removeUnusedCollections(List<TaasCollection> list) {
    final Language sourceLang = Core.getProject().getProjectProperties().getSourceLanguage();
    final Language targetLang = Core.getProject().getProjectProperties().getTargetLanguage();
    for (int i = 0; i < list.size(); i++) {
        TaasCollection c = list.get(i);
        if (getCountForLanguage(c, sourceLang) == 0 || getCountForLanguage(c, targetLang) == 0) {
            list.remove(i);
            i--;
        }
    }
}
Also used : TaasCollection(gen.taas.TaasCollection) TaasLanguage(gen.taas.TaasLanguage) Language(org.omegat.util.Language)

Example 8 with Language

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

the class MainWindowMenuHandler method toolsAlignFilesMenuItemActionPerformed.

public void toolsAlignFilesMenuItemActionPerformed() {
    AlignFilePickerController picker = new AlignFilePickerController();
    if (Core.getProject().isProjectLoaded()) {
        String srcRoot = Core.getProject().getProjectProperties().getSourceRoot();
        String curFile = Core.getEditor().getCurrentFile();
        if (curFile != null) {
            picker.setSourceFile(srcRoot + curFile);
        }
        picker.setSourceDefaultDir(srcRoot);
        picker.setDefaultSaveDir(Core.getProject().getProjectProperties().getTMRoot());
        picker.setSourceLanguage(Core.getProject().getProjectProperties().getSourceLanguage());
        picker.setTargetLanguage(Core.getProject().getProjectProperties().getTargetLanguage());
    } else {
        String srcLang = Preferences.getPreference(Preferences.SOURCE_LOCALE);
        if (!StringUtil.isEmpty(srcLang)) {
            picker.setSourceLanguage(new Language(srcLang));
        }
        String trgLang = Preferences.getPreference(Preferences.TARGET_LOCALE);
        if (!StringUtil.isEmpty(trgLang)) {
            picker.setTargetLanguage(new Language(trgLang));
        }
    }
    picker.show(mainWindow);
}
Also used : AlignFilePickerController(org.omegat.gui.align.AlignFilePickerController) Language(org.omegat.util.Language) NearString(org.omegat.core.matching.NearString)

Example 9 with Language

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

the class DictionariesManagerTest method setUp.

@Before
public final void setUp() throws Exception {
    manager = new DictionariesManager(new IDictionaries() {

        @Override
        public void refresh() {
        }

        @Override
        public void addDictionaryFactory(IDictionaryFactory factory) {
        }

        @Override
        public void removeDictionaryFactory(IDictionaryFactory factory) {
        }
    }) {

        @Override
        protected boolean doFuzzyMatching() {
            return true;
        }
    };
    manager.setIndexLanguage(new Language(Locale.ENGLISH));
    manager.setTokenizer(new DefaultTokenizer());
    PrintWriter fw = new PrintWriter(IGNORE_FILE, "UTF-8");
    fw.println(IGNORE_WORD);
    fw.close();
    assertFalse(fw.checkError());
}
Also used : Language(org.omegat.util.Language) DefaultTokenizer(org.omegat.tokenizer.DefaultTokenizer) IDictionaries(org.omegat.gui.dictionaries.IDictionaries) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 10 with Language

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

the class SegmenterTest method testGlue.

/**
 * Test of glue method, of class org.omegat.core.segmentation.Segmenter.
 */
@Test
public void testGlue() {
    List<StringBuilder> spaces = new ArrayList<StringBuilder>();
    List<Rule> brules = new ArrayList<Rule>();
    String oldString = "<br7>\n\n<br5>\n\nother";
    List<String> segments = segmenter.segment(new Language("en"), oldString, spaces, brules);
    String newString = segmenter.glue(new Language("en"), new Language("fr"), segments, spaces, brules);
    assertEquals(oldString, newString);
}
Also used : Language(org.omegat.util.Language) ArrayList(java.util.ArrayList) 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