From dd97fe35ee25eb02995930ee09a6ebda307513a0 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 10 Aug 2011 03:51:21 +0000 Subject: [PATCH] * display a set of common languages first in language preference list --- .../net/sourceforge/filebot/ui/Language.java | 48 ++++++++--- .../filebot/ui/Language.properties | 86 ++++++++++--------- .../filebot/ui/panel/rename/RenamePanel.java | 17 +--- .../panel/subtitle/LanguageComboBoxModel.java | 12 +-- .../ui/panel/subtitle/SubtitlePanel.java | 5 +- 5 files changed, 88 insertions(+), 80 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/Language.java b/source/net/sourceforge/filebot/ui/Language.java index 928eb9aa..361b3969 100644 --- a/source/net/sourceforge/filebot/ui/Language.java +++ b/source/net/sourceforge/filebot/ui/Language.java @@ -2,7 +2,13 @@ package net.sourceforge.filebot.ui; +import static java.util.Arrays.*; +import static java.util.Collections.*; + import java.util.Comparator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; import java.util.ResourceBundle; import java.util.Set; @@ -54,26 +60,46 @@ public class Language { ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); try { - return new Language(code, bundle.getString(code)); + return new Language(code, bundle.getString(code + ".name")); } catch (Exception e) { return null; } } - public static Language[] availableLanguages() { - ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); - Set languageCodeSet = bundle.keySet(); + public static List getLanguages(String... codes) { + Language[] languages = new Language[codes.length]; - Language[] languages = new Language[languageCodeSet.size()]; - int size = 0; - - // fill languages array - for (String code : languageCodeSet) { - languages[size++] = new Language(code, bundle.getString(code)); + for (int i = 0; i < codes.length; i++) { + languages[i] = getLanguage(codes[i]); } - return languages; + return asList(languages); } + + public static List availableLanguages() { + ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); + return getLanguages(bundle.getString("languages.all").split(",")); + } + + + public static List commonLanguages() { + ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); + return getLanguages(bundle.getString("languages.common").split(",")); + } + + + public static List preferredLanguages() { + Set codes = new LinkedHashSet(); + + // English | System language | common languages + codes.add("en"); + codes.add(Locale.getDefault().getLanguage()); + + ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); + addAll(codes, bundle.getString("languages.common").split(",")); + + return getLanguages(codes.toArray(new String[0])); + } } diff --git a/source/net/sourceforge/filebot/ui/Language.properties b/source/net/sourceforge/filebot/ui/Language.properties index 3196623e..5b213bb0 100644 --- a/source/net/sourceforge/filebot/ui/Language.properties +++ b/source/net/sourceforge/filebot/ui/Language.properties @@ -1,43 +1,45 @@ # available languages -sq: Albanian -ar: Arabic -hy: Armenian -pb: Brazilian -bg: Bulgarian -ca: Catalan -zh: Chinese -hr: Croatian -cs: Czech -da: Danish -nl: Dutch -en: English -et: Estonian -fi: Finnish -fr: French -de: German -el: Greek -he: Hebrew -hi: Hindi -hu: Hungarian -id: Indonesian -it: Italian -ja: Japanese -ko: Korean -lv: Latvian -lt: Lithuanian -mk: Macedonian -ms: Malay -no: Norwegian -fa: Persian -pl: Polish -pt: Portuguese -ro: Romanian -ru: Russian -sr: Serbian -sk: Slovak -sl: Slovenian -es: Spanish -sv: Swedish -th: Thai -tr: Turkish -vi: Vietnamese +languages.all = sq,ar,hy,pb,bg,ca,zh,hr,cs,da,nl,en,et,fi,fr,de,el,he,hi,hu,id,it,ja,ko,lv,lt,mk,ms,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sv,th,tr,vi +languages.common = en,de,fr,es,pt,ru,ja,zh +sq.name: Albanian +ar.name: Arabic +hy.name: Armenian +pb.name: Brazilian +bg.name: Bulgarian +ca.name: Catalan +zh.name: Chinese +hr.name: Croatian +cs.name: Czech +da.name: Danish +nl.name: Dutch +en.name: English +et.name: Estonian +fi.name: Finnish +fr.name: French +de.name: German +el.name: Greek +he.name: Hebrew +hi.name: Hindi +hu.name: Hungarian +id.name: Indonesian +it.name: Italian +ja.name: Japanese +ko.name: Korean +lv.name: Latvian +lt.name: Lithuanian +mk.name: Macedonian +ms.name: Malay +no.name: Norwegian +fa.name: Persian +pl.name: Polish +pt.name: Portuguese +ro.name: Romanian +ru.name: Russian +sr.name: Serbian +sk.name: Slovak +sl.name: Slovenian +es.name: Spanish +sv.name: Swedish +th.name: Thai +tr.name: Turkish +vi.name: Vietnamese diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index 58ba0593..3a124b61 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -15,8 +15,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -193,18 +191,9 @@ public class RenamePanel extends JComponent { @Override public void actionPerformed(ActionEvent evt) { - List languages = new LinkedList(); - - // all languages - Language[] availableLanguages = Language.availableLanguages(); - Arrays.sort(availableLanguages, Language.ALPHABETIC_ORDER); - Collections.addAll(languages, availableLanguages); - - // guess preferred language - if (!Locale.getDefault().equals(Locale.ENGLISH)) { - languages.add(0, Language.getLanguage(Locale.getDefault().getLanguage())); - } - languages.add(0, Language.getLanguage("en")); + List languages = new ArrayList(); + languages.addAll(Language.preferredLanguages()); // add preferred languages first + languages.addAll(Language.availableLanguages()); // then others JList message = new JList(languages.toArray()); message.setCellRenderer(new DefaultListCellRenderer() { diff --git a/source/net/sourceforge/filebot/ui/panel/subtitle/LanguageComboBoxModel.java b/source/net/sourceforge/filebot/ui/panel/subtitle/LanguageComboBoxModel.java index 69fcb39b..78083fc3 100644 --- a/source/net/sourceforge/filebot/ui/panel/subtitle/LanguageComboBoxModel.java +++ b/source/net/sourceforge/filebot/ui/panel/subtitle/LanguageComboBoxModel.java @@ -6,8 +6,6 @@ import static net.sourceforge.filebot.ui.Language.*; import java.util.AbstractList; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -25,15 +23,7 @@ class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel { private List favorites = new Favorites(2); - private List values; - - - public LanguageComboBoxModel() { - values = Arrays.asList(availableLanguages()); - - // sort languages by name - Collections.sort(values, ALPHABETIC_ORDER); - } + private List values = availableLanguages(); @Override diff --git a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java index c2a1f31d..ef24be6c 100644 --- a/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/subtitle/SubtitlePanel.java @@ -2,6 +2,7 @@ package net.sourceforge.filebot.ui.panel.subtitle; +import static net.sourceforge.filebot.ui.Language.*; import static net.sourceforge.filebot.ui.panel.subtitle.LanguageComboBoxModel.*; import java.awt.Color; @@ -56,13 +57,13 @@ public class SubtitlePanel extends AbstractSearchPanel