about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-03 10:59:31 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-03 16:59:31 +0200
commit8c5ad23b24b17efc0660928d0b02ddbebc6f2939 (patch)
tree71177649c7f13ce16b80397f987a2ff9cfb97d65 /app/lib
parent53384b0ffe4fd8cfcced4fe2945acd814c676088 (diff)
Language improvements, replace whatlanguage with CLD (#2753)
* add failing en specs

* add cld2 gem

* Replace WhatLanguage with CLD
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/language_detector.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb
index 9a32d6a64..8c1751beb 100644
--- a/app/lib/language_detector.rb
+++ b/app/lib/language_detector.rb
@@ -9,11 +9,23 @@ class LanguageDetector
   end
 
   def to_iso_s
-    WhatLanguage.new(:all).language_iso(text_without_urls) || default_locale.to_sym
+    detected_language_code || default_locale.to_sym
   end
 
   private
 
+  def detected_language_code
+    detected_language[:code].to_sym if detected_language_reliable?
+  end
+
+  def detected_language
+    @_detected_language ||= CLD.detect_language(text_without_urls)
+  end
+
+  def detected_language_reliable?
+    detected_language[:reliable]
+  end
+
   def text_without_urls
     text.dup.tap do |new_text|
       URI.extract(new_text).each do |url|