1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 17:28:51 -05:00

* include 3-letter language codes in Language config file

This commit is contained in:
Reinhard Pointner 2013-12-31 07:28:30 +00:00
parent e1409b5c30
commit b9f76c407c
13 changed files with 133 additions and 148 deletions

View File

@ -1,4 +1,4 @@
package net.sourceforge.filebot.ui;
package net.sourceforge.filebot;
import static java.util.Arrays.*;
import static java.util.Collections.*;
@ -12,16 +12,26 @@ import java.util.Set;
public class Language {
private final String code;
private final String iso2;
private final String iso3;
private final String name;
public Language(String code, String name) {
this.code = code;
public Language(String iso2, String iso3, String name) {
this.iso2 = iso2;
this.iso3 = iso3;
this.name = name;
}
public String getCode() {
return code;
return iso2;
}
public String getISO2() {
return iso2;
}
public String getISO3() {
return iso3;
}
public String getName() {
@ -39,7 +49,7 @@ public class Language {
@Override
public Language clone() {
return new Language(code, name);
return new Language(iso2, iso3, name);
}
public static final Comparator<Language> ALPHABETIC_ORDER = new Comparator<Language>() {
@ -54,12 +64,14 @@ public class Language {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());
try {
return new Language(code, bundle.getString(code + ".name"));
String[] values = bundle.getString(code).split("\\t", 2);
return new Language(code, values[0], values[1]);
} catch (Exception e) {
if (code == null || code.isEmpty()) {
return null;
}
return new Language(code, new Locale(code).getDisplayLanguage(Locale.ROOT));
Locale locale = new Locale(code);
return new Language(locale.getLanguage(), locale.getISO3Language(), locale.getDisplayLanguage(Locale.ENGLISH));
}
}
@ -74,7 +86,16 @@ public class Language {
}
public static Language getLanguage(Locale locale) {
return locale == null ? null : getLanguageByName(locale.getDisplayLanguage(Locale.ENGLISH));
if (locale == null)
return null;
String code = locale.getLanguage();
for (Language it : availableLanguages()) {
if (it.getISO2().equals(code) || it.getISO3().equals(code)) {
return it;
}
}
return null;
}
public static Language getLanguageByName(String name) {
@ -87,17 +108,12 @@ public class Language {
}
public static String getISO3LanguageCodeByName(String languageName) {
Language language = Language.getLanguageByName(languageName);
if (language != null) {
try {
return new Locale(language.getCode()).getISO3Language();
return Language.getLanguageByName(languageName).getISO3();
} catch (Exception e) {
return language.getCode();
}
}
return null;
}
}
public static List<Language> availableLanguages() {
ResourceBundle bundle = ResourceBundle.getBundle(Language.class.getName());

View File

@ -0,0 +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.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

View File

@ -57,7 +57,7 @@ import net.sourceforge.filebot.similarity.SeriesNameMatcher;
import net.sourceforge.filebot.similarity.SimilarityComparator;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.subtitle.SubtitleFormat;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.vfs.MemoryFile;
import net.sourceforge.filebot.web.AudioTrack;
import net.sourceforge.filebot.web.Episode;

View File

@ -33,7 +33,7 @@ import net.sourceforge.filebot.similarity.MetricCascade;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
import net.sourceforge.filebot.similarity.SequenceMatchSimilarity;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.vfs.ArchiveType;
import net.sourceforge.filebot.vfs.MemoryFile;
import net.sourceforge.filebot.web.SearchResult;

View File

@ -1,45 +0,0 @@
# 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.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

@ -1,7 +1,7 @@
package net.sourceforge.filebot.ui;
import static java.awt.event.ItemEvent.*;
import static net.sourceforge.filebot.ui.Language.*;
import static net.sourceforge.filebot.Language.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
@ -16,6 +16,7 @@ import javax.swing.JComboBox;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.Settings;
public class LanguageComboBox extends JComboBox {

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.ui;
import java.awt.Color;
import java.awt.Component;
@ -12,10 +10,10 @@ import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.tuned.ui.DashedSeparator;
public class LanguageComboBoxCellRenderer implements ListCellRenderer {
private Border padding = new EmptyBorder(2, 2, 2, 2);
@ -24,13 +22,11 @@ public class LanguageComboBoxCellRenderer implements ListCellRenderer {
private ListCellRenderer base;
public LanguageComboBoxCellRenderer(final ListCellRenderer base) {
this.base = base;
this.padding = new CompoundBorder(padding, ((JLabel) base).getBorder());
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel c = (JLabel) base.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

View File

@ -1,6 +1,6 @@
package net.sourceforge.filebot.ui;
import static net.sourceforge.filebot.ui.Language.*;
import static net.sourceforge.filebot.Language.*;
import java.util.AbstractList;
import java.util.ArrayList;
@ -10,9 +10,11 @@ import java.util.Set;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import net.sourceforge.filebot.Language;
public class LanguageComboBoxModel extends AbstractListModel implements ComboBoxModel {
public static final Language ALL_LANGUAGES = new Language("undefined", "All Languages");
public static final Language ALL_LANGUAGES = new Language("", "", "All Languages");
private Language defaultLanguage;
private Language selection;

View File

@ -32,7 +32,7 @@ import net.sourceforge.filebot.ui.AbstractSearchPanel;
import net.sourceforge.filebot.ui.FileBotList;
import net.sourceforge.filebot.ui.FileBotListExportHandler;
import net.sourceforge.filebot.ui.FileBotTab;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.ui.LanguageComboBox;
import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.ui.transfer.ArrayTransferable;

View File

@ -53,7 +53,7 @@ import net.sourceforge.filebot.StandardRenameAction;
import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.format.MediaBindingBean;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.ui.rename.FormatDialog.Mode;
import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture;
import net.sourceforge.filebot.web.AudioTrack;

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.ui.subtitle;
import static java.util.Collections.*;
import static net.sourceforge.filebot.MediaTypes.*;
@ -20,14 +18,13 @@ import java.util.ResourceBundle;
import javax.swing.SwingWorker;
import javax.swing.event.SwingPropertyChangeSupport;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.vfs.ArchiveType;
import net.sourceforge.filebot.vfs.MemoryFile;
import net.sourceforge.filebot.web.SubtitleDescriptor;
import net.sourceforge.filebot.web.SubtitleProvider;
import net.sourceforge.tuned.FileUtilities;
public class SubtitlePackage {
private final SubtitleProvider provider;
@ -35,13 +32,12 @@ public class SubtitlePackage {
private final Language language;
private Download download;
public SubtitlePackage(SubtitleProvider provider, SubtitleDescriptor subtitle) {
this.provider = provider;
this.subtitle = subtitle;
// resolve language name
this.language = new Language(languageCodeByName.get(subtitle.getLanguageName()), subtitle.getLanguageName());
this.language = new Language(languageCodeByName.get(subtitle.getLanguageName()), Language.getISO3LanguageCodeByName(subtitle.getLanguageName()), subtitle.getLanguageName());
// initialize download worker
download = new Download(subtitle);
@ -58,32 +54,26 @@ public class SubtitlePackage {
});
}
public SubtitleProvider getProvider() {
return provider;
}
public String getName() {
return subtitle.getName();
}
public Language getLanguage() {
return language;
}
public String getType() {
return subtitle.getType();
}
public Download getDownload() {
return download;
}
public void reset() {
// cancel old download
download.cancel(false);
@ -101,47 +91,35 @@ public class SubtitlePackage {
pcs.firePropertyChange("download.phase", old.getPhase(), download.getPhase());
}
@Override
public String toString() {
return subtitle.getName();
}
private final PropertyChangeSupport pcs = new SwingPropertyChangeSupport(this, true);
public void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}
public static class Download extends SwingWorker<List<MemoryFile>, Void> {
enum Phase {
PENDING,
WAITING,
DOWNLOADING,
EXTRACTING,
DONE
PENDING, WAITING, DOWNLOADING, EXTRACTING, DONE
}
private final SubtitleDescriptor subtitle;
private Phase current = Phase.PENDING;
private Download(SubtitleDescriptor descriptor) {
this.subtitle = descriptor;
}
public void start() {
setPhase(Phase.WAITING);
@ -149,7 +127,6 @@ public class SubtitlePackage {
execute();
}
@Override
protected List<MemoryFile> doInBackground() throws Exception {
setPhase(Phase.DOWNLOADING);
@ -186,7 +163,6 @@ public class SubtitlePackage {
return vfs;
}
private List<MemoryFile> extract(ArchiveType archiveType, ByteBuffer data) throws IOException {
List<MemoryFile> vfs = new ArrayList<MemoryFile>();
@ -208,13 +184,11 @@ public class SubtitlePackage {
return vfs;
}
@Override
protected void done() {
setPhase(Phase.DONE);
}
private void setPhase(Phase phase) {
Phase old = current;
current = phase;
@ -222,24 +196,20 @@ public class SubtitlePackage {
firePropertyChange("phase", old, phase);
}
public boolean isStarted() {
return current != Phase.PENDING;
}
public Phase getPhase() {
return current;
}
}
/**
* 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);

View File

@ -36,7 +36,7 @@ import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.Settings;
import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.ui.AbstractSearchPanel;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.ui.LanguageComboBox;
import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.OpenSubtitlesClient;

View File

@ -52,7 +52,7 @@ import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.Analytics;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.media.MediaDetection;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.Language;
import net.sourceforge.filebot.ui.LanguageComboBox;
import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Movie;
@ -423,7 +423,7 @@ public class SubtitleUploadDialog extends JDialog {
icon = ResourceManager.getIcon("database.ok");
break;
case Identifying:
text = "Auto-detect missing information";
text = "Auto-detecting missing information";
icon = ResourceManager.getIcon("action.export");
break;
case IdentificationRequired: