FIX: Translation should return overrides first before attempting to fallback.

https://meta.discourse.org/t/errors-after-migrating-to-a-new-version-1-9-0-beta3/65709/14?u=tgxworld
This commit is contained in:
Guo Xiang Tan 2017-07-11 12:51:12 +09:00
parent f529cb1674
commit b605d5d61b
2 changed files with 15 additions and 3 deletions

View File

@ -74,9 +74,8 @@ module I18n
existing_translations = super(locale, key, scope, options)
overrides = options.dig(:overrides, locale)
if overrides && existing_translations
if options[:count]
if overrides && !scope&.include?(:models)
if existing_translations && options[:count]
remapped_translations =
if existing_translations.is_a?(Hash)
Hash[existing_translations.map { |k, v| ["#{key}.#{k}", v] }]

View File

@ -163,6 +163,19 @@ describe I18n::Backend::DiscourseI18n do
.to eq('snow is the new queen')
end
it "returns override if it exists before falling back" do
I18n.backend.store_translations(:en, got: 'winter')
expect(I18n.translate('got', default: '')).to eq('winter')
expect(I18n.with_locale(:ru) { I18n.translate('got', default: '') }).to eq('winter')
TranslationOverride.upsert!('ru', 'got', "summer")
I18n.backend.store_translations(:en, got: 'winter')
expect(I18n.translate('got', default: '')).to eq('winter')
expect(I18n.with_locale(:ru) { I18n.translate('got', default: '') }).to eq('summer')
end
it 'supports ActiveModel::Naming#human' do
Fish = Class.new(ActiveRecord::Base)