A platform for community discussion. Free, open, simple.
FIX: Looking up translation overrides by symbol failed when `count` is used (#12896)
Gerhard Schlager4f36f604c8a6
diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rbindex 52b387e69aa..2fd498f6687 100644--- a/lib/i18n/backend/discourse_i18n.rb+++ b/lib/i18n/backend/discourse_i18n.rb@@ -91,6 +91,7 @@ module I18nreturn existing_translations if scope.is_a?(Array) && scope.include?(:models)overrides = options.dig(:overrides, locale)+ key = key.to_sif overridesif options[:count]@@ -112,7 +113,7 @@ module I18nresult = {}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)endreturn result if result.size > 0enddiff --git a/spec/components/freedom_patches/translate_accelerator_spec.rb b/spec/components/freedom_patches/translate_accelerator_spec.rbindex effea352b3f..cd52c799ede 100644--- a/spec/components/freedom_patches/translate_accelerator_spec.rb+++ b/spec/components/freedom_patches/translate_accelerator_spec.rb@@ -179,6 +179,12 @@ describe "translate accelerator" doexpect(I18n.t('items', count: 1)).to eq('one fish')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" dooverride_translation('en_GB', 'items.one', 'one fish')override_translation('en_GB', 'items.other', '%{count} fishies')