FIX: Load translation overrides for more than one locale

This commit is contained in:
Gerhard Schlager 2016-02-13 23:07:10 +01:00
parent 2e875d3cca
commit 80c9fa4dca
2 changed files with 12 additions and 4 deletions

View File

@ -105,8 +105,7 @@ module I18n
by_site = @overrides_by_site[site] by_site = @overrides_by_site[site]
by_locale = nil unless by_site && by_site.has_key?(locale)
unless by_site
by_site = @overrides_by_site[site] = {} by_site = @overrides_by_site[site] = {}
# Load overrides # Load overrides

View File

@ -15,6 +15,7 @@ describe I18n::Backend::DiscourseI18n do
end end
after do after do
I18n.locale = :en
I18n.reload! I18n.reload!
end end
@ -78,15 +79,23 @@ describe I18n::Backend::DiscourseI18n do
end end
describe 'with overrides' do describe 'with overrides' do
it 'returns the overriden key' do it 'returns the overridden key' do
TranslationOverride.upsert!('en', 'foo', 'Overwritten foo') TranslationOverride.upsert!('en', 'foo', 'Overwritten foo')
expect(I18n.translate('foo')).to eq('Overwritten foo') expect(I18n.translate('foo')).to eq('Overwritten foo')
TranslationOverride.upsert!('en', 'foo', 'new value') TranslationOverride.upsert!('en', 'foo', 'new value')
I18n.reload!
expect(I18n.translate('foo')).to eq('new value') expect(I18n.translate('foo')).to eq('new value')
end end
it 'returns the overridden key after switching the locale' do
TranslationOverride.upsert!('en', 'foo', 'Overwritten foo in EN')
TranslationOverride.upsert!('de', 'foo', 'Overwritten foo in DE')
expect(I18n.translate('foo')).to eq('Overwritten foo in EN')
I18n.locale = :de
expect(I18n.translate('foo')).to eq('Overwritten foo in DE')
end
it "can be searched" do it "can be searched" do
TranslationOverride.upsert!('en', 'wat', 'Overwritten value') TranslationOverride.upsert!('en', 'wat', 'Overwritten value')
expect(I18n.search('wat', backend: backend)).to eq({'wat' => 'Overwritten value'}) expect(I18n.search('wat', backend: backend)).to eq({'wat' => 'Overwritten value'})