about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-09-08 12:32:22 +0200
committerGitHub <noreply@github.com>2017-09-08 12:32:22 +0200
commit1caf11ddcc029d9e7735ab3b90607ab2d6973034 (patch)
treef4642058d59360ea44ddf937c22b3835077719a6 /app/lib
parent95f018a3d4f02ff4ce77d7b1cfa9a79fce3ce99a (diff)
Fix language filter codes (#4841)
* Fix language filter codes

CLD3 returns BCP-47 language identifier, filter settings expect
identifiers in the ISO 639-1 format. Convert between formats,
and exclude duplicate languages from filter choices (zh-CN->zh)

* Fix zh name
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/language_detector.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb
index cc7509fdc..1d9932b52 100644
--- a/app/lib/language_detector.rb
+++ b/app/lib/language_detector.rb
@@ -20,7 +20,16 @@ class LanguageDetector
   private
 
   def detected_language_code
-    result.language.to_sym if detected_language_reliable?
+    iso6391(result.language).to_sym if detected_language_reliable?
+  end
+
+  def iso6391(bcp47)
+    iso639 = bcp47.split('-').first
+
+    # CLD3 returns grandfathered language code for Hebrew
+    return 'he' if iso639 == 'iw'
+
+    ISO_639.find(iso639).alpha2
   end
 
   def result