mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
* fix language code resolution issues
This commit is contained in:
parent
b93e91c7e5
commit
09332e8aca
@ -13,13 +13,22 @@ import java.util.Set;
|
||||
|
||||
public class Language implements Serializable {
|
||||
|
||||
// ISO 639-1 code
|
||||
private final String iso2;
|
||||
|
||||
// ISO 639-2/T code
|
||||
private final String iso3;
|
||||
|
||||
// ISO 639-2/B code
|
||||
private final String iso3b;
|
||||
|
||||
// Language 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.iso3 = iso3;
|
||||
this.iso3b = iso3b;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -48,9 +57,13 @@ public class Language implements Serializable {
|
||||
return new Locale(getCode());
|
||||
}
|
||||
|
||||
public boolean matches(String code) {
|
||||
return iso2.equalsIgnoreCase(code) || iso3.equalsIgnoreCase(code) || iso3b.equalsIgnoreCase(code) || name.equalsIgnoreCase(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
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>() {
|
||||
@ -65,8 +78,8 @@ public class Language implements Serializable {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
|
||||
|
||||
try {
|
||||
String[] values = bundle.getString(code).split("\\t", 2);
|
||||
return new Language(code, values[0], values[1]);
|
||||
String[] values = bundle.getString(code).split("\\t", 3);
|
||||
return new Language(code, values[0], values[1], values[2]);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
@ -86,7 +99,7 @@ public class Language implements Serializable {
|
||||
if (locale != null) {
|
||||
String code = locale.getLanguage();
|
||||
for (Language it : availableLanguages()) {
|
||||
if (it.getISO2().equals(code) || it.getISO3().equals(code)) {
|
||||
if (it.matches(code)) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
@ -96,7 +109,7 @@ public class Language implements Serializable {
|
||||
|
||||
public static Language findLanguage(String lang) {
|
||||
for (Language it : availableLanguages()) {
|
||||
if (lang.equalsIgnoreCase(it.getISO2()) || lang.equalsIgnoreCase(it.getISO3()) || lang.equalsIgnoreCase(it.getName())) {
|
||||
if (it.matches(lang)) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
@ -113,7 +126,7 @@ public class Language implements Serializable {
|
||||
|
||||
public static List<Language> availableLanguages() {
|
||||
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() {
|
||||
|
@ -1,45 +1,45 @@
|
||||
# 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
|
||||
sq: sqi Albanian
|
||||
ar: ara Arabic
|
||||
hy: hye Armenian
|
||||
pb: pob Brazilian
|
||||
bg: bul Bulgarian
|
||||
ca: cat Catalan
|
||||
zh: zho Chinese
|
||||
hr: hrv Croatian
|
||||
cs: ces Czech
|
||||
da: dan Danish
|
||||
nl: nld Dutch
|
||||
en: eng English
|
||||
et: est Estonian
|
||||
fi: fin Finnish
|
||||
fr: fra French
|
||||
de: deu German
|
||||
el: ell Greek
|
||||
he: heb Hebrew
|
||||
hi: hin Hindi
|
||||
hu: hun Hungarian
|
||||
id: ind Indonesian
|
||||
it: ita Italian
|
||||
ja: jpn Japanese
|
||||
ko: kor Korean
|
||||
lv: lav Latvian
|
||||
lt: lit Lithuanian
|
||||
mk: mkd Macedonian
|
||||
ms: msa Malay
|
||||
no: nor Norwegian
|
||||
fa: fas Persian
|
||||
pl: pol Polish
|
||||
pt: por Portuguese
|
||||
ro: ron Romanian
|
||||
ru: rus Russian
|
||||
sr: srp Serbian
|
||||
sk: slk Slovak
|
||||
sl: slv Slovenian
|
||||
es: spa Spanish
|
||||
sv: swe Swedish
|
||||
th: tha Thai
|
||||
tr: tur Turkish
|
||||
vi: vie Vietnamese
|
||||
sq: sqi alb Albanian
|
||||
ar: ara ara Arabic
|
||||
hy: hye arm Armenian
|
||||
pb: pob pob Brazilian
|
||||
bg: bul bul Bulgarian
|
||||
ca: cat cat Catalan
|
||||
zh: zho chi Chinese
|
||||
hr: hrv hrv Croatian
|
||||
cs: ces cze Czech
|
||||
da: dan dan Danish
|
||||
nl: nld dut Dutch
|
||||
en: eng eng English
|
||||
et: est est Estonian
|
||||
fi: fin fin Finnish
|
||||
fr: fra fre French
|
||||
de: deu ger German
|
||||
el: ell gre Greek
|
||||
he: heb heb Hebrew
|
||||
hi: hin hin Hindi
|
||||
hu: hun hun Hungarian
|
||||
id: ind ind Indonesian
|
||||
it: ita ita Italian
|
||||
ja: jpn jpn Japanese
|
||||
ko: kor kor Korean
|
||||
lv: lav lav Latvian
|
||||
lt: lit lit Lithuanian
|
||||
mk: mkd mac Macedonian
|
||||
ms: msa may Malay
|
||||
no: nor nor Norwegian
|
||||
fa: fas per Persian
|
||||
pl: pol pol Polish
|
||||
pt: por por Portuguese
|
||||
ro: ron rum Romanian
|
||||
ru: rus rus Russian
|
||||
sr: srp srp Serbian
|
||||
sk: slk slo Slovak
|
||||
sl: slv slv Slovenian
|
||||
es: spa spa Spanish
|
||||
sv: swe swe Swedish
|
||||
th: tha tha Thai
|
||||
tr: tur tur Turkish
|
||||
vi: vie vie Vietnamese
|
||||
|
@ -13,7 +13,7 @@ import net.filebot.Language;
|
||||
|
||||
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 selection;
|
||||
|
@ -9,11 +9,7 @@ import java.beans.PropertyChangeSupport;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.event.SwingPropertyChangeSupport;
|
||||
@ -30,6 +26,7 @@ public class SubtitlePackage {
|
||||
private final SubtitleProvider provider;
|
||||
private final SubtitleDescriptor subtitle;
|
||||
private final Language language;
|
||||
|
||||
private Download download;
|
||||
|
||||
public SubtitlePackage(SubtitleProvider provider, SubtitleDescriptor subtitle) {
|
||||
@ -37,7 +34,7 @@ public class SubtitlePackage {
|
||||
this.subtitle = subtitle;
|
||||
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user