From aff5407a1a5bf55b0b17a07d066a026f8925c415 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 22 Apr 2017 21:55:27 +0800 Subject: [PATCH] Fix for Brazilian Portuguese language preferences when using OpenSubtitles @see https://www.filebot.net/forums/viewtopic.php?f=8&t=4992 --- source/net/filebot/web/OpenSubtitlesClient.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index 1bd68e3b..bda82ff4 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -465,6 +465,17 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS return subLanguageMap; } + protected String getLanguageCode(Locale locale) { + switch (locale.toString()) { + case "pt_BR": + return "pb"; + case "zh_TW": + return "tw"; + default: + return locale.getLanguage(); + } + } + protected String[] getLanguageFilter(Locale locale) { return locale == null || locale.getLanguage().isEmpty() ? new String[0] : new String[] { getSubLanguageID(locale) }; } @@ -476,7 +487,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS String subLanguageID = null; try { - subLanguageID = getSubLanguageMap().get(locale.getLanguage()); + subLanguageID = getSubLanguageMap().get(getLanguageCode(locale)); } catch (Exception e) { throw new IllegalStateException("Failed to retrieve subtitle language map", e); }