mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
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:
@ -74,9 +74,8 @@ module I18n
|
|||||||
existing_translations = super(locale, key, scope, options)
|
existing_translations = super(locale, key, scope, options)
|
||||||
overrides = options.dig(:overrides, locale)
|
overrides = options.dig(:overrides, locale)
|
||||||
|
|
||||||
if overrides && existing_translations
|
if overrides && !scope&.include?(:models)
|
||||||
if options[:count]
|
if existing_translations && options[:count]
|
||||||
|
|
||||||
remapped_translations =
|
remapped_translations =
|
||||||
if existing_translations.is_a?(Hash)
|
if existing_translations.is_a?(Hash)
|
||||||
Hash[existing_translations.map { |k, v| ["#{key}.#{k}", v] }]
|
Hash[existing_translations.map { |k, v| ["#{key}.#{k}", v] }]
|
||||||
|
@ -163,6 +163,19 @@ describe I18n::Backend::DiscourseI18n do
|
|||||||
.to eq('snow is the new queen')
|
.to eq('snow is the new queen')
|
||||||
end
|
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
|
it 'supports ActiveModel::Naming#human' do
|
||||||
Fish = Class.new(ActiveRecord::Base)
|
Fish = Class.new(ActiveRecord::Base)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user