* display a set of common languages first in language preference list

This commit is contained in:
Reinhard Pointner 2011-08-10 03:51:21 +00:00
parent 949b1ce864
commit dd97fe35ee
5 changed files with 88 additions and 80 deletions

View File

@ -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<String> languageCodeSet = bundle.keySet();
public static List<Language> 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<Language> availableLanguages() {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
return getLanguages(bundle.getString("languages.all").split(","));
}
public static List<Language> commonLanguages() {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
return getLanguages(bundle.getString("languages.common").split(","));
}
public static List<Language> preferredLanguages() {
Set<String> codes = new LinkedHashSet<String>();
// 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]));
}
}

View File

@ -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

View File

@ -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<Language> languages = new LinkedList<Language>();
// 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<Language> languages = new ArrayList<Language>();
languages.addAll(Language.preferredLanguages()); // add preferred languages first
languages.addAll(Language.availableLanguages()); // then others
JList message = new JList(languages.toArray());
message.setCellRenderer(new DefaultListCellRenderer() {

View File

@ -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<Language> favorites = new Favorites(2);
private List<Language> values;
public LanguageComboBoxModel() {
values = Arrays.asList(availableLanguages());
// sort languages by name
Collections.sort(values, ALPHABETIC_ORDER);
}
private List<Language> values = availableLanguages();
@Override

View File

@ -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<SubtitleProvider, Subtitl
// restore favorite languages
for (String favoriteLanguage : persistentFavoriteLanguages) {
languageModel.favorites().add(languageModel.favorites().size(), Language.getLanguage(favoriteLanguage));
languageModel.favorites().add(languageModel.favorites().size(), getLanguage(favoriteLanguage));
}
// guess favorite languages
if (languageModel.favorites().isEmpty()) {
for (Locale locale : new Locale[] { Locale.getDefault(), Locale.ENGLISH }) {
languageModel.favorites().add(Language.getLanguage(locale.getLanguage()));
languageModel.favorites().add(getLanguage(locale.getLanguage()));
}
}