FIX: Do not override existing translations.

This commit is contained in:
Guo Xiang Tan 2015-12-31 23:20:19 +08:00
parent eb7417ea0c
commit 556cd1e3f8
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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')