0
0
Fork 0

Language detection refactor (#2099)

* Extract detect_language to separate class

* Use default locale, not just en

* Add spec to confirm that whatlanguage cant identify empty string

* Allow account locale to override default in language detector

* PostStatusService supplies an account to detect language
This commit is contained in:
Matt Jankowski 2017-04-18 16:20:12 -04:00 committed by Eugen
parent 0a7588282a
commit 297c11dba2
4 changed files with 106 additions and 3 deletions

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
class LanguageDetector
attr_reader :text, :account
def initialize(text, account = nil)
@text = text
@account = account
end
def to_iso_s
WhatLanguage.new(:all).language_iso(text) || default_locale.to_sym
end
private
def default_locale
account&.user&.locale || I18n.default_locale
end
end