From 9709ef3a42cda1199af0a56aed642b14971837e2 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 8 Nov 2017 11:02:55 +0100 Subject: [PATCH] Fix TheMovieDB language codes for Hebrew and Indonesian @see https://www.filebot.net/forums/viewtopic.php?f=6&t=4898#p30996 --- source/net/filebot/web/TMDbClient.java | 25 +++++++++++++++++------- test/net/filebot/web/TMDbClientTest.java | 10 ++++++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 2fdee213..8e8aff18 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -383,16 +383,27 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider { } protected String getLanguageCode(Locale locale) { - // require 2-letter language code String language = locale.getLanguage(); - if (language.length() == 2) { - if (locale.getCountry().length() == 2) { - return locale.getLanguage() + '-' + locale.getCountry(); // e.g. es-MX - } - return locale.getLanguage(); // e.g. en + + // Note: ISO 639 is not a stable standard— some languages' codes have changed. + // Locale's constructor recognizes both the new and the old codes for the languages whose codes have changed, + // but this function always returns the old code. + switch (language) { + case "iw": + return "he"; // Hebrew + case "in": + return "id"; // Indonesian + case "": + return null; // empty language code } - return null; + // require 2-letter language code + String country = locale.getCountry(); + if (country.length() > 0) { + return language + '-' + country; // e.g. es-MX + } + + return language; } } diff --git a/test/net/filebot/web/TMDbClientTest.java b/test/net/filebot/web/TMDbClientTest.java index 8b7c1b71..26df8626 100644 --- a/test/net/filebot/web/TMDbClientTest.java +++ b/test/net/filebot/web/TMDbClientTest.java @@ -92,11 +92,17 @@ public class TMDbClientTest { assertEquals("Transformers", movie.getName()); assertEquals("2007-06-27", movie.getReleased().toString()); assertEquals("PG-13", movie.getCertification()); - assertEquals("{NL=12, FR=U, BG=C, TH=PG-13, DK=11, SE=15 År, GB=12A, KR=12세 관람가, HU=12, BR=10, AU=M, DE=12, GR=13, US=PG-13}", movie.getCertifications().toString()); + assertEquals("{NL=12, AU=M, BG=C, GR=13, KR=12세 관람가, DK=11, GB=12A, TH=PG-13, SE=15, BR=10, HU=12, DE=12, FR=U, US=PG-13}", movie.getCertifications().toString()); assertEquals("[es, en]", movie.getSpokenLanguages().toString()); assertEquals("Shia LaBeouf", movie.getActors().get(0)); assertEquals("Michael Bay", movie.getDirector()); - assertEquals("Trailer 2 [Trailer] [720] [en_US]", movie.getTrailers().get(0).toString()); + assertEquals("Trailer 2 [Trailer] [720] [en_US] [YouTube::ejxQOv53lXs]", movie.getTrailers().get(0).toString()); + } + + @Test + public void getMovieInfoHebrew() throws Exception { + MovieInfo movie = db.getMovieInfo(new Movie(1260396), Locale.forLanguageTag("he-IL"), false); + assertEquals("שבעה", movie.getName()); } @Test