2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Gitlab::I18n, feature_category: :internationalization do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:user) { create(:user, preferred_language: :es) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe '.selectable_locales' do
|
2021-06-08 01:23:25 +05:30
|
|
|
include StubLanguagesTranslationPercentage
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it 'does not return languages with default translation levels 60%' do
|
2021-06-08 01:23:25 +05:30
|
|
|
stub_languages_translation_percentage(pt_BR: 0, en: 100, es: 65)
|
|
|
|
|
|
|
|
expect(described_class.selectable_locales).to eq({
|
|
|
|
'en' => 'English',
|
|
|
|
'es' => 'Spanish - español'
|
|
|
|
})
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it 'does not return languages with less than 100% translation levels' do
|
|
|
|
stub_languages_translation_percentage(pt_BR: 0, en: 100, es: 65)
|
|
|
|
|
|
|
|
expect(described_class.selectable_locales(100)).to eq({ 'en' => 'English' })
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '.locale=' do
|
|
|
|
after do
|
|
|
|
described_class.use_default_locale
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the locale based on current user preferred language' do
|
|
|
|
described_class.locale = user.preferred_language
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(FastGettext.locale).to eq('es')
|
|
|
|
expect(::I18n.locale).to eq(:es)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '.use_default_locale' do
|
|
|
|
it 'resets the locale to the default language' do
|
|
|
|
described_class.locale = user.preferred_language
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
described_class.use_default_locale
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(FastGettext.locale).to eq('en')
|
|
|
|
expect(::I18n.locale).to eq(:en)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
describe '.pluralisation_rule' do
|
|
|
|
context 'when overridden' do
|
|
|
|
before do
|
|
|
|
# Internally, FastGettext sets
|
|
|
|
# Thread.current[:fast_gettext_pluralisation_rule].
|
|
|
|
# Our patch patches `FastGettext.pluralisation_rule` instead.
|
|
|
|
FastGettext.pluralisation_rule = :something
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns custom definition regardless' do
|
|
|
|
expect(FastGettext.pluralisation_rule).to eq(Gitlab::I18n::Pluralization)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|