diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb index 8b131d324..612b32306 100644 --- a/lib/freedom_patches/translate_accelerator.rb +++ b/lib/freedom_patches/translate_accelerator.rb @@ -105,8 +105,7 @@ module I18n by_site = @overrides_by_site[site] - by_locale = nil - unless by_site + unless by_site && by_site.has_key?(locale) by_site = @overrides_by_site[site] = {} # Load overrides diff --git a/spec/components/discourse_i18n_spec.rb b/spec/components/discourse_i18n_spec.rb index 33722e92b..f41b9caaf 100644 --- a/spec/components/discourse_i18n_spec.rb +++ b/spec/components/discourse_i18n_spec.rb @@ -15,6 +15,7 @@ describe I18n::Backend::DiscourseI18n do end after do + I18n.locale = :en I18n.reload! end @@ -78,15 +79,23 @@ describe I18n::Backend::DiscourseI18n do end describe 'with overrides' do - it 'returns the overriden key' do + it 'returns the overridden key' do TranslationOverride.upsert!('en', 'foo', 'Overwritten foo') expect(I18n.translate('foo')).to eq('Overwritten foo') TranslationOverride.upsert!('en', 'foo', 'new value') - I18n.reload! expect(I18n.translate('foo')).to eq('new value') 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 TranslationOverride.upsert!('en', 'wat', 'Overwritten value') expect(I18n.search('wat', backend: backend)).to eq({'wat' => 'Overwritten value'})