diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb index ee133d5066e..988bf87d5f6 100644 --- a/lib/i18n/backend/discourse_i18n.rb +++ b/lib/i18n/backend/discourse_i18n.rb @@ -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] }] diff --git a/spec/components/discourse_i18n_spec.rb b/spec/components/discourse_i18n_spec.rb index c3fc16da1a2..7db8d9a6cc9 100644 --- a/spec/components/discourse_i18n_spec.rb +++ b/spec/components/discourse_i18n_spec.rb @@ -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)