mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: Looking up translation overrides by symbol failed when count
is used (#12896)
This commit is contained in:
@ -91,6 +91,7 @@ module I18n
|
|||||||
return existing_translations if scope.is_a?(Array) && scope.include?(:models)
|
return existing_translations if scope.is_a?(Array) && scope.include?(:models)
|
||||||
|
|
||||||
overrides = options.dig(:overrides, locale)
|
overrides = options.dig(:overrides, locale)
|
||||||
|
key = key.to_s
|
||||||
|
|
||||||
if overrides
|
if overrides
|
||||||
if options[:count]
|
if options[:count]
|
||||||
@ -112,7 +113,7 @@ module I18n
|
|||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
remapped_translations.merge(overrides).each do |k, v|
|
remapped_translations.merge(overrides).each do |k, v|
|
||||||
result[k.split('.').last.to_sym] = v if k != key && k.start_with?(key.to_s)
|
result[k.split('.').last.to_sym] = v if k != key && k.start_with?(key)
|
||||||
end
|
end
|
||||||
return result if result.size > 0
|
return result if result.size > 0
|
||||||
end
|
end
|
||||||
|
@ -179,6 +179,12 @@ describe "translate accelerator" do
|
|||||||
expect(I18n.t('items', count: 1)).to eq('one fish')
|
expect(I18n.t('items', count: 1)).to eq('one fish')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works with strings and symbols for non-pluralized string when count is given" do
|
||||||
|
override_translation('en', 'fish', 'trout')
|
||||||
|
expect(I18n.t(:fish, count: 1)).to eq('trout')
|
||||||
|
expect(I18n.t('fish', count: 1)).to eq('trout')
|
||||||
|
end
|
||||||
|
|
||||||
it "supports one and other with fallback locale" do
|
it "supports one and other with fallback locale" do
|
||||||
override_translation('en_GB', 'items.one', 'one fish')
|
override_translation('en_GB', 'items.one', 'one fish')
|
||||||
override_translation('en_GB', 'items.other', '%{count} fishies')
|
override_translation('en_GB', 'items.other', '%{count} fishies')
|
||||||
|
Reference in New Issue
Block a user