def detect(text, account)
input_text = prepare_text(text)
return if input_text.blank?
+
detect_language_code(input_text) || default_locale(account)
end
def detect_language_code(text)
return if unreliable_input?(text)
+
result = @identifier.find_language(text)
iso6391(result.language.to_s).to_sym if result.reliable?
end
end
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
describe 'detect' do
let(:account_without_user_locale) { Fabricate(:user, locale: nil).account }
+ let(:account_remote) { Fabricate(:account, domain: 'joinmastodon.org') }
it 'detects english language for basic strings' do
strings = [
end
end
+ describe 'remote user' do
+ it 'nil for foreign user when language is not present' do
+ string = '안녕하세요'
+ result = described_class.instance.detect(string, account_remote)
+
+ expect(result).to eq nil
+ end
+ end
+
describe 'with a non-`en` default locale' do
around(:each) do |example|
before = I18n.default_locale