* fix language code resolution issues

This commit is contained in:
Reinhard Pointner 2014-08-27 19:53:10 +00:00
parent b93e91c7e5
commit 09332e8aca
4 changed files with 66 additions and 73 deletions

View File

@ -13,13 +13,22 @@ import java.util.Set;
public class Language implements Serializable { public class Language implements Serializable {
// ISO 639-1 code
private final String iso2; private final String iso2;
// ISO 639-2/T code
private final String iso3; private final String iso3;
// ISO 639-2/B code
private final String iso3b;
// Language name
private final String name; private final String name;
public Language(String iso2, String iso3, String name) { public Language(String iso2, String iso3, String iso3b, String name) {
this.iso2 = iso2; this.iso2 = iso2;
this.iso3 = iso3; this.iso3 = iso3;
this.iso3b = iso3b;
this.name = name; this.name = name;
} }
@ -48,9 +57,13 @@ public class Language implements Serializable {
return new Locale(getCode()); return new Locale(getCode());
} }
public boolean matches(String code) {
return iso2.equalsIgnoreCase(code) || iso3.equalsIgnoreCase(code) || iso3b.equalsIgnoreCase(code) || name.equalsIgnoreCase(code);
}
@Override @Override
public Language clone() { public Language clone() {
return new Language(iso2, iso3, name); return new Language(iso2, iso3, iso3b, name);
} }
public static final Comparator<Language> ALPHABETIC_ORDER = new Comparator<Language>() { public static final Comparator<Language> ALPHABETIC_ORDER = new Comparator<Language>() {
@ -65,8 +78,8 @@ public class Language implements Serializable {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
try { try {
String[] values = bundle.getString(code).split("\\t", 2); String[] values = bundle.getString(code).split("\\t", 3);
return new Language(code, values[0], values[1]); return new Language(code, values[0], values[1], values[2]);
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
@ -86,7 +99,7 @@ public class Language implements Serializable {
if (locale != null) { if (locale != null) {
String code = locale.getLanguage(); String code = locale.getLanguage();
for (Language it : availableLanguages()) { for (Language it : availableLanguages()) {
if (it.getISO2().equals(code) || it.getISO3().equals(code)) { if (it.matches(code)) {
return it; return it;
} }
} }
@ -96,7 +109,7 @@ public class Language implements Serializable {
public static Language findLanguage(String lang) { public static Language findLanguage(String lang) {
for (Language it : availableLanguages()) { for (Language it : availableLanguages()) {
if (lang.equalsIgnoreCase(it.getISO2()) || lang.equalsIgnoreCase(it.getISO3()) || lang.equalsIgnoreCase(it.getName())) { if (it.matches(lang)) {
return it; return it;
} }
} }
@ -113,7 +126,7 @@ public class Language implements Serializable {
public static List<Language> availableLanguages() { public static List<Language> availableLanguages() {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName()); ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
return getLanguages(bundle.getString("languages.all").split(",")); return getLanguages(bundle.getString("languages.ui").split(","));
} }
public static List<Language> commonLanguages() { public static List<Language> commonLanguages() {

View File

@ -1,45 +1,45 @@
# available languages # available languages
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.ui = 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 languages.common = en,de,fr,es,pt,ru,ja,zh
sq: sqi Albanian sq: sqi alb Albanian
ar: ara Arabic ar: ara ara Arabic
hy: hye Armenian hy: hye arm Armenian
pb: pob Brazilian pb: pob pob Brazilian
bg: bul Bulgarian bg: bul bul Bulgarian
ca: cat Catalan ca: cat cat Catalan
zh: zho Chinese zh: zho chi Chinese
hr: hrv Croatian hr: hrv hrv Croatian
cs: ces Czech cs: ces cze Czech
da: dan Danish da: dan dan Danish
nl: nld Dutch nl: nld dut Dutch
en: eng English en: eng eng English
et: est Estonian et: est est Estonian
fi: fin Finnish fi: fin fin Finnish
fr: fra French fr: fra fre French
de: deu German de: deu ger German
el: ell Greek el: ell gre Greek
he: heb Hebrew he: heb heb Hebrew
hi: hin Hindi hi: hin hin Hindi
hu: hun Hungarian hu: hun hun Hungarian
id: ind Indonesian id: ind ind Indonesian
it: ita Italian it: ita ita Italian
ja: jpn Japanese ja: jpn jpn Japanese
ko: kor Korean ko: kor kor Korean
lv: lav Latvian lv: lav lav Latvian
lt: lit Lithuanian lt: lit lit Lithuanian
mk: mkd Macedonian mk: mkd mac Macedonian
ms: msa Malay ms: msa may Malay
no: nor Norwegian no: nor nor Norwegian
fa: fas Persian fa: fas per Persian
pl: pol Polish pl: pol pol Polish
pt: por Portuguese pt: por por Portuguese
ro: ron Romanian ro: ron rum Romanian
ru: rus Russian ru: rus rus Russian
sr: srp Serbian sr: srp srp Serbian
sk: slk Slovak sk: slk slo Slovak
sl: slv Slovenian sl: slv slv Slovenian
es: spa Spanish es: spa spa Spanish
sv: swe Swedish sv: swe swe Swedish
th: tha Thai th: tha tha Thai
tr: tur Turkish tr: tur tur Turkish
vi: vie Vietnamese vi: vie vie Vietnamese

View File

@ -13,7 +13,7 @@ import net.filebot.Language;
public class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel { public class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel {
public static final Language ALL_LANGUAGES = new Language("undefined", "undefined", "All Languages"); public static final Language ALL_LANGUAGES = new Language("undefined", "undefined", "undefined", "All Languages");
private Language defaultLanguage; private Language defaultLanguage;
private Language selection; private Language selection;

View File

@ -9,11 +9,7 @@ import java.beans.PropertyChangeSupport;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import javax.swing.event.SwingPropertyChangeSupport; import javax.swing.event.SwingPropertyChangeSupport;
@ -30,6 +26,7 @@ public class SubtitlePackage {
private final SubtitleProvider provider; private final SubtitleProvider provider;
private final SubtitleDescriptor subtitle; private final SubtitleDescriptor subtitle;
private final Language language; private final Language language;
private Download download; private Download download;
public SubtitlePackage(SubtitleProvider provider, SubtitleDescriptor subtitle) { public SubtitlePackage(SubtitleProvider provider, SubtitleDescriptor subtitle) {
@ -37,7 +34,7 @@ public class SubtitlePackage {
this.subtitle = subtitle; this.subtitle = subtitle;
// resolve language name // resolve language name
this.language = new Language(languageCodeByName.get(subtitle.getLanguageName()), Language.getISO3LanguageCodeByName(subtitle.getLanguageName()), subtitle.getLanguageName()); this.language = Language.findLanguage(subtitle.getLanguageName());
// initialize download worker // initialize download worker
download = new Download(subtitle); download = new Download(subtitle);
@ -205,21 +202,4 @@ public class SubtitlePackage {
} }
} }
/**
* Map english language name to language code.
*/
private static final Map<String, String> languageCodeByName = mapLanguageCodeByName();
private static Map<String, String> mapLanguageCodeByName() {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName(), Locale.ENGLISH);
Map<String, String> map = new HashMap<String, String>();
for (String code : bundle.keySet()) {
map.put(bundle.getString(code), code);
}
return map;
}
} }