0
0
Fork 0

Language improvements, replace whatlanguage with CLD (#2753)

* add failing en specs

* add cld2 gem

* Replace WhatLanguage with CLD
This commit is contained in:
Matt Jankowski 2017-05-03 10:59:31 -04:00 committed by Eugen Rochko
parent 53384b0ffe
commit 8c5ad23b24
4 changed files with 32 additions and 12 deletions

View file

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