* display a set of common languages first in language preference list
This commit is contained in:
parent
949b1ce864
commit
dd97fe35ee
|
@ -2,7 +2,13 @@
|
||||||
package net.sourceforge.filebot.ui;
|
package net.sourceforge.filebot.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.Collections.*;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -54,26 +60,46 @@ public class Language {
|
||||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new Language(code, bundle.getString(code));
|
return new Language(code, bundle.getString(code + ".name"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Language[] availableLanguages() {
|
public static List<Language> getLanguages(String... codes) {
|
||||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
Language[] languages = new Language[codes.length];
|
||||||
Set<String> languageCodeSet = bundle.keySet();
|
|
||||||
|
|
||||||
Language[] languages = new Language[languageCodeSet.size()];
|
for (int i = 0; i < codes.length; i++) {
|
||||||
int size = 0;
|
languages[i] = getLanguage(codes[i]);
|
||||||
|
|
||||||
// fill languages array
|
|
||||||
for (String code : languageCodeSet) {
|
|
||||||
languages[size++] = new Language(code, bundle.getString(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,45 @@
|
||||||
# available languages
|
# available languages
|
||||||
sq: Albanian
|
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
|
||||||
ar: Arabic
|
languages.common = en,de,fr,es,pt,ru,ja,zh
|
||||||
hy: Armenian
|
sq.name: Albanian
|
||||||
pb: Brazilian
|
ar.name: Arabic
|
||||||
bg: Bulgarian
|
hy.name: Armenian
|
||||||
ca: Catalan
|
pb.name: Brazilian
|
||||||
zh: Chinese
|
bg.name: Bulgarian
|
||||||
hr: Croatian
|
ca.name: Catalan
|
||||||
cs: Czech
|
zh.name: Chinese
|
||||||
da: Danish
|
hr.name: Croatian
|
||||||
nl: Dutch
|
cs.name: Czech
|
||||||
en: English
|
da.name: Danish
|
||||||
et: Estonian
|
nl.name: Dutch
|
||||||
fi: Finnish
|
en.name: English
|
||||||
fr: French
|
et.name: Estonian
|
||||||
de: German
|
fi.name: Finnish
|
||||||
el: Greek
|
fr.name: French
|
||||||
he: Hebrew
|
de.name: German
|
||||||
hi: Hindi
|
el.name: Greek
|
||||||
hu: Hungarian
|
he.name: Hebrew
|
||||||
id: Indonesian
|
hi.name: Hindi
|
||||||
it: Italian
|
hu.name: Hungarian
|
||||||
ja: Japanese
|
id.name: Indonesian
|
||||||
ko: Korean
|
it.name: Italian
|
||||||
lv: Latvian
|
ja.name: Japanese
|
||||||
lt: Lithuanian
|
ko.name: Korean
|
||||||
mk: Macedonian
|
lv.name: Latvian
|
||||||
ms: Malay
|
lt.name: Lithuanian
|
||||||
no: Norwegian
|
mk.name: Macedonian
|
||||||
fa: Persian
|
ms.name: Malay
|
||||||
pl: Polish
|
no.name: Norwegian
|
||||||
pt: Portuguese
|
fa.name: Persian
|
||||||
ro: Romanian
|
pl.name: Polish
|
||||||
ru: Russian
|
pt.name: Portuguese
|
||||||
sr: Serbian
|
ro.name: Romanian
|
||||||
sk: Slovak
|
ru.name: Russian
|
||||||
sl: Slovenian
|
sr.name: Serbian
|
||||||
es: Spanish
|
sk.name: Slovak
|
||||||
sv: Swedish
|
sl.name: Slovenian
|
||||||
th: Thai
|
es.name: Spanish
|
||||||
tr: Turkish
|
sv.name: Swedish
|
||||||
vi: Vietnamese
|
th.name: Thai
|
||||||
|
tr.name: Turkish
|
||||||
|
vi.name: Vietnamese
|
||||||
|
|
|
@ -15,8 +15,6 @@ import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -193,18 +191,9 @@ public class RenamePanel extends JComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
List<Language> languages = new LinkedList<Language>();
|
List<Language> languages = new ArrayList<Language>();
|
||||||
|
languages.addAll(Language.preferredLanguages()); // add preferred languages first
|
||||||
// all languages
|
languages.addAll(Language.availableLanguages()); // then others
|
||||||
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"));
|
|
||||||
|
|
||||||
JList message = new JList(languages.toArray());
|
JList message = new JList(languages.toArray());
|
||||||
message.setCellRenderer(new DefaultListCellRenderer() {
|
message.setCellRenderer(new DefaultListCellRenderer() {
|
||||||
|
|
|
@ -6,8 +6,6 @@ import static net.sourceforge.filebot.ui.Language.*;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -25,15 +23,7 @@ class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel {
|
||||||
|
|
||||||
private List<Language> favorites = new Favorites(2);
|
private List<Language> favorites = new Favorites(2);
|
||||||
|
|
||||||
private List<Language> values;
|
private List<Language> values = availableLanguages();
|
||||||
|
|
||||||
|
|
||||||
public LanguageComboBoxModel() {
|
|
||||||
values = Arrays.asList(availableLanguages());
|
|
||||||
|
|
||||||
// sort languages by name
|
|
||||||
Collections.sort(values, ALPHABETIC_ORDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
package net.sourceforge.filebot.ui.panel.subtitle;
|
package net.sourceforge.filebot.ui.panel.subtitle;
|
||||||
|
|
||||||
|
|
||||||
|
import static net.sourceforge.filebot.ui.Language.*;
|
||||||
import static net.sourceforge.filebot.ui.panel.subtitle.LanguageComboBoxModel.*;
|
import static net.sourceforge.filebot.ui.panel.subtitle.LanguageComboBoxModel.*;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
@ -56,13 +57,13 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
|
|
||||||
// restore favorite languages
|
// restore favorite languages
|
||||||
for (String favoriteLanguage : persistentFavoriteLanguages) {
|
for (String favoriteLanguage : persistentFavoriteLanguages) {
|
||||||
languageModel.favorites().add(languageModel.favorites().size(), Language.getLanguage(favoriteLanguage));
|
languageModel.favorites().add(languageModel.favorites().size(), getLanguage(favoriteLanguage));
|
||||||
}
|
}
|
||||||
|
|
||||||
// guess favorite languages
|
// guess favorite languages
|
||||||
if (languageModel.favorites().isEmpty()) {
|
if (languageModel.favorites().isEmpty()) {
|
||||||
for (Locale locale : new Locale[] { Locale.getDefault(), Locale.ENGLISH }) {
|
for (Locale locale : new Locale[] { Locale.getDefault(), Locale.ENGLISH }) {
|
||||||
languageModel.favorites().add(Language.getLanguage(locale.getLanguage()));
|
languageModel.favorites().add(getLanguage(locale.getLanguage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue