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

* {lang} binding returns Language object now because Locale has compatibility issues with the various standards

This commit is contained in:
Reinhard Pointner 2013-12-31 07:59:58 +00:00
parent b9f76c407c
commit b2b0610579
5 changed files with 21 additions and 19 deletions

View File

@ -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,15 +87,15 @@ public class Language {
}
public static Language getLanguage(Locale locale) {
if (locale == null)
return null;
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;
}

View File

@ -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<File> 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<String> episodes = new ArrayList<String>();

View File

@ -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")

View File

@ -98,7 +98,7 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
String text = searchTextField.getText().trim();
int season = seasonSpinnerModel.getSeason();
SortOrder order = (SortOrder) sortOrderComboBox.getSelectedItem();
Locale language = languageComboBox.getModel().getSelectedItem().toLocale();
Locale language = languageComboBox.getModel().getSelectedItem().getLocale();
return new EpisodeListRequestProcessor(new EpisodeListRequest(provider, text, season, order, language));
};

View File

@ -708,7 +708,7 @@ public class SubtitleUploadDialog extends JDialog {
try {
mapping.setState(SubtitleMapping.Status.Uploading);
database.uploadSubtitle(mapping.getIdentity(), mapping.getLanguage().toLocale(), mapping.getVideo(), mapping.getSubtitle());
database.uploadSubtitle(mapping.getIdentity(), mapping.getLanguage().getLocale(), mapping.getVideo(), mapping.getSubtitle());
mapping.setState(SubtitleMapping.Status.UploadComplete);
Analytics.trackEvent(database.getName(), "UploadSubtitle", mapping.getLanguage().getName(), 1);