2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-25 06:09:18 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'i18n/backend/fallback_locale_list'
|
|
|
|
|
|
|
|
describe I18n::Backend::FallbackLocaleList do
|
|
|
|
let(:list) { I18n::Backend::FallbackLocaleList.new }
|
|
|
|
|
|
|
|
it "works when default_locale is English" do
|
|
|
|
SiteSetting.default_locale = :en
|
|
|
|
|
|
|
|
expect(list[:ru]).to eq([:ru, :en])
|
|
|
|
expect(list[:en]).to eq([:en])
|
2019-05-15 17:43:00 -04:00
|
|
|
end
|
|
|
|
|
2021-01-20 15:32:22 -05:00
|
|
|
it "works when default_locale is English (UK)" do
|
|
|
|
SiteSetting.default_locale = :en_GB
|
2019-05-15 17:43:00 -04:00
|
|
|
|
2020-05-06 16:57:14 -04:00
|
|
|
expect(list[:ru]).to eq([:ru, :en])
|
2021-01-20 15:32:22 -05:00
|
|
|
expect(list[:en_GB]).to eq([:en_GB, :en])
|
2019-05-15 17:43:00 -04:00
|
|
|
expect(list[:en]).to eq([:en])
|
2018-01-25 06:09:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "works when default_locale is not English" do
|
|
|
|
SiteSetting.default_locale = :de
|
|
|
|
|
2020-05-06 16:57:14 -04:00
|
|
|
expect(list[:ru]).to eq([:ru, :en])
|
2018-01-25 06:09:18 -05:00
|
|
|
expect(list[:de]).to eq([:de, :en])
|
2019-05-10 19:38:58 -04:00
|
|
|
expect(list[:en]).to eq([:en])
|
2021-01-20 15:32:22 -05:00
|
|
|
expect(list[:en_GB]).to eq([:en_GB, :en])
|
2018-01-25 06:09:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when plugin registered fallback locale" do
|
|
|
|
before do
|
|
|
|
DiscoursePluginRegistry.register_locale("es_MX", fallbackLocale: "es")
|
|
|
|
DiscoursePluginRegistry.register_locale("de_AT", fallbackLocale: "de")
|
2020-05-06 16:57:14 -04:00
|
|
|
DiscoursePluginRegistry.register_locale("de_AT-formal", fallbackLocale: "de_AT")
|
2018-01-25 06:09:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
DiscoursePluginRegistry.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works when default_locale is English" do
|
|
|
|
SiteSetting.default_locale = :en
|
|
|
|
|
|
|
|
expect(list[:de_AT]).to eq([:de_AT, :de, :en])
|
2020-05-06 16:57:14 -04:00
|
|
|
expect(list[:"de_AT-formal"]).to eq([:"de_AT-formal", :de_AT, :de, :en])
|
|
|
|
expect(list[:de]).to eq([:de, :en])
|
|
|
|
expect(list[:en]).to eq([:en])
|
|
|
|
end
|
|
|
|
|
2021-01-20 15:32:22 -05:00
|
|
|
it "works when default_locale is English (UK)" do
|
|
|
|
SiteSetting.default_locale = :en_GB
|
2020-05-06 16:57:14 -04:00
|
|
|
|
|
|
|
expect(list[:de_AT]).to eq([:de_AT, :de, :en])
|
|
|
|
expect(list[:"de_AT-formal"]).to eq([:"de_AT-formal", :de_AT, :de, :en])
|
2018-01-25 06:09:18 -05:00
|
|
|
expect(list[:de]).to eq([:de, :en])
|
|
|
|
expect(list[:en]).to eq([:en])
|
2021-01-20 15:32:22 -05:00
|
|
|
expect(list[:en_GB]).to eq([:en_GB, :en])
|
2018-01-25 06:09:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "works when default_locale is not English" do
|
|
|
|
SiteSetting.default_locale = :de
|
|
|
|
|
2020-05-06 16:57:14 -04:00
|
|
|
expect(list[:es_MX]).to eq([:es_MX, :es, :en])
|
|
|
|
expect(list[:"de_AT-formal"]).to eq([:"de_AT-formal", :de_AT, :de, :en])
|
|
|
|
expect(list[:es]).to eq([:es, :en])
|
2019-05-10 19:38:58 -04:00
|
|
|
expect(list[:en]).to eq([:en])
|
2018-01-25 06:09:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|