diff --git a/source/net/sourceforge/filebot/Language.java b/source/net/sourceforge/filebot/Language.java index b69b0f68..3398f9e2 100644 --- a/source/net/sourceforge/filebot/Language.java +++ b/source/net/sourceforge/filebot/Language.java @@ -3,6 +3,7 @@ package net.sourceforge.filebot; import static java.util.Arrays.*; import static java.util.Collections.*; +import java.io.Serializable; import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; @@ -10,7 +11,7 @@ import java.util.Locale; import java.util.ResourceBundle; import java.util.Set; -public class Language { +public class Language implements Serializable { private final String iso2; private final String iso3; @@ -40,10 +41,10 @@ public class Language { @Override public String toString() { - return name; + return iso3; } - public Locale toLocale() { + public Locale getLocale() { return new Locale(getCode()); } @@ -86,14 +87,14 @@ public class Language { } public static Language getLanguage(Locale locale) { - if (locale == null) - return null; - - String code = locale.getLanguage(); - for (Language it : availableLanguages()) { - if (it.getISO2().equals(code) || it.getISO3().equals(code)) { - return it; + if (locale != null) { + String code = locale.getLanguage(); + for (Language it : availableLanguages()) { + if (it.getISO2().equals(code) || it.getISO3().equals(code)) { + return it; + } } + return new Language(code, locale.getISO3Language(), locale.getDisplayName(Locale.ENGLISH)); } return null; } diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index d3f17076..1e78bc12 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -82,7 +82,7 @@ public class CmdlineOperations implements CmdlineInterface { ExpressionFormat format = (formatExpression != null) ? new ExpressionFormat(formatExpression) : null; ExpressionFilter filter = (filterExpression != null) ? new ExpressionFilter(filterExpression) : null; File outputDir = (output != null && output.length() > 0) ? new File(output).getAbsoluteFile() : null; - Locale locale = getLanguage(lang).toLocale(); + Locale locale = getLanguage(lang).getLocale(); ConflictAction conflictAction = ConflictAction.forName(conflict); if (getEpisodeListProvider(db) != null) { @@ -683,12 +683,12 @@ public class CmdlineOperations implements CmdlineInterface { if (query == null) { try { List videoFiles = filter(files, VIDEO_FILES); - querySet.addAll(detectSeriesNames(videoFiles, language.toLocale())); + querySet.addAll(detectSeriesNames(videoFiles, language.getLocale())); // auto-detect movie names for (File f : videoFiles) { if (!isEpisode(f.getName(), false)) { - for (Movie movie : detectMovie(f, null, null, language.toLocale(), strict)) { + for (Movie movie : detectMovie(f, null, null, language.getLocale(), strict)) { querySet.add(movie.getName()); } } @@ -1039,7 +1039,7 @@ public class CmdlineOperations implements CmdlineInterface { ExpressionFormat format = (expression != null) ? new ExpressionFormat(expression) : null; EpisodeListProvider service = (db == null) ? TheTVDB : getEpisodeListProvider(db); SortOrder sortOrder = SortOrder.forName(sortOrderName); - Locale locale = getLanguage(languageName).toLocale(); + Locale locale = getLanguage(languageName).getLocale(); SearchResult hit = selectSearchResult(query, service.search(query, locale), false).get(0); List episodes = new ArrayList(); diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index 21af4eaa..52cabfcb 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -27,6 +27,7 @@ import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.filebot.Cache; +import net.sourceforge.filebot.Language; import net.sourceforge.filebot.MediaTypes; import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.hash.HashType; @@ -420,13 +421,13 @@ public class MediaBindingBean { } @Define("lang") - public Locale detectSubtitleLanguage() throws Exception { + public Language detectSubtitleLanguage() throws Exception { // make sure media file is defined checkMediaFile(); Locale languageSuffix = releaseInfo.getLanguageSuffix(FileUtilities.getName(mediaFile)); if (languageSuffix != null) - return languageSuffix; + return Language.getLanguage(languageSuffix); // require subtitle file if (!SUBTITLE_FILES.accept(mediaFile)) { @@ -445,7 +446,7 @@ public class MediaBindingBean { } // try statistical language detection - return WebServices.OpenSubtitles.detectLanguage(readFile(mediaFile)); + return Language.getLanguage(WebServices.OpenSubtitles.detectLanguage(readFile(mediaFile))); } @Define("actors") diff --git a/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java b/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java index cb08ec92..955eee26 100644 --- a/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java +++ b/source/net/sourceforge/filebot/ui/episodelist/EpisodeListPanel.java @@ -98,7 +98,7 @@ public class EpisodeListPanel extends AbstractSearchPanel