|
|
@ -12,6 +12,7 @@ class LanguageDetector
|
|
|
|
def detect(text, account)
|
|
|
|
def detect(text, account)
|
|
|
|
input_text = prepare_text(text)
|
|
|
|
input_text = prepare_text(text)
|
|
|
|
return if input_text.blank?
|
|
|
|
return if input_text.blank?
|
|
|
|
|
|
|
|
|
|
|
|
detect_language_code(input_text) || default_locale(account)
|
|
|
|
detect_language_code(input_text) || default_locale(account)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -33,6 +34,7 @@ class LanguageDetector
|
|
|
|
|
|
|
|
|
|
|
|
def detect_language_code(text)
|
|
|
|
def detect_language_code(text)
|
|
|
|
return if unreliable_input?(text)
|
|
|
|
return if unreliable_input?(text)
|
|
|
|
|
|
|
|
|
|
|
|
result = @identifier.find_language(text)
|
|
|
|
result = @identifier.find_language(text)
|
|
|
|
iso6391(result.language.to_s).to_sym if result.reliable?
|
|
|
|
iso6391(result.language.to_s).to_sym if result.reliable?
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -75,6 +77,6 @@ class LanguageDetector
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def default_locale(account)
|
|
|
|
def default_locale(account)
|
|
|
|
account.user_locale&.to_sym || I18n.default_locale
|
|
|
|
return account.user_locale&.to_sym || I18n.default_locale if account.local?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|