From 09332e8aca48b9ae4014997ea332610653e07430 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 27 Aug 2014 19:53:10 +0000 Subject: [PATCH] * fix language code resolution issues --- source/net/filebot/Language.java | 27 ++++-- source/net/filebot/Language.properties | 86 +++++++++---------- .../net/filebot/ui/LanguageComboBoxModel.java | 2 +- .../filebot/ui/subtitle/SubtitlePackage.java | 24 +----- 4 files changed, 66 insertions(+), 73 deletions(-) diff --git a/source/net/filebot/Language.java b/source/net/filebot/Language.java index 95c23553..ffe41313 100644 --- a/source/net/filebot/Language.java +++ b/source/net/filebot/Language.java @@ -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 ALPHABETIC_ORDER = new Comparator() { @@ -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 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 commonLanguages() { diff --git a/source/net/filebot/Language.properties b/source/net/filebot/Language.properties index d187af8b..bc3321bf 100644 --- a/source/net/filebot/Language.properties +++ b/source/net/filebot/Language.properties @@ -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 diff --git a/source/net/filebot/ui/LanguageComboBoxModel.java b/source/net/filebot/ui/LanguageComboBoxModel.java index 9f4e3ce6..70b5b739 100644 --- a/source/net/filebot/ui/LanguageComboBoxModel.java +++ b/source/net/filebot/ui/LanguageComboBoxModel.java @@ -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; diff --git a/source/net/filebot/ui/subtitle/SubtitlePackage.java b/source/net/filebot/ui/subtitle/SubtitlePackage.java index 59ce4b31..e7e92d7c 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePackage.java +++ b/source/net/filebot/ui/subtitle/SubtitlePackage.java @@ -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 languageCodeByName = mapLanguageCodeByName(); - - private static Map mapLanguageCodeByName() { - ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName(), Locale.ENGLISH); - - Map map = new HashMap(); - - for (String code : bundle.keySet()) { - map.put(bundle.getString(code), code); - } - - return map; - } - }