diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb index 851878fcf2c..c4bccbf122e 100644 --- a/lib/i18n/backend/discourse_i18n.rb +++ b/lib/i18n/backend/discourse_i18n.rb @@ -70,7 +70,7 @@ module I18n if options[:overrides] && existing_translations if options[:count] - existing_translations = + remapped_translations = if existing_translations.is_a?(Hash) Hash[existing_translations.map { |k, v| ["#{key}.#{k}", v] }] elsif existing_translations.is_a?(String) @@ -79,7 +79,7 @@ module I18n result = {} - existing_translations.merge(options[:overrides]).each do |k, v| + remapped_translations.merge(options[:overrides]).each do |k, v| result[k.split('.').last.to_sym] = v if k != key && k.start_with?(key.to_s) end return result if result.size > 0 diff --git a/spec/components/discourse_i18n_spec.rb b/spec/components/discourse_i18n_spec.rb index daebd478092..40dbf4a2ef4 100644 --- a/spec/components/discourse_i18n_spec.rb +++ b/spec/components/discourse_i18n_spec.rb @@ -111,6 +111,13 @@ describe I18n::Backend::DiscourseI18n do expect(I18n.translate('wat', count: 123)).to eq('goodbye 123') end + it 'ignores interpolation named count if it is not applicable' do + TranslationOverride.upsert!('en', 'test', 'goodbye') + I18n.backend.store_translations(:en, test: 'foo') + I18n.backend.store_translations(:en, wat: 'bar') + expect(I18n.translate('wat', count: 1)).to eq('bar') + end + it 'supports one and other' do TranslationOverride.upsert!('en', 'items.one', 'one fish') TranslationOverride.upsert!('en', 'items.other', '%{count} fishies')