From 43360471a5fd2f85a2da6e845854387c6c098425 Mon Sep 17 00:00:00 2001 From: Fabio L Janiszevski Date: Tue, 3 Mar 2020 13:22:03 -0300 Subject: [PATCH 1/2] Add the test to fail --- test/backend/pluralization_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/backend/pluralization_test.rb b/test/backend/pluralization_test.rb index 1518efdb..d955818e 100644 --- a/test/backend/pluralization_test.rb +++ b/test/backend/pluralization_test.rb @@ -39,6 +39,11 @@ def setup assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx) end + test "pluralization picks one for 1 if the entry has attributes hash on unknown locale" do + @entry[:attributes] = { :field => 'field', :second => 'second' } + assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :pirate) + end + test "Fallbacks can pick up rules from fallback locales, too" do assert_equal @rule, I18n.backend.send(:pluralizer, :'xx-XX') end From 572bca8b5eb55178eed622ed6befb9512017bf4d Mon Sep 17 00:00:00 2001 From: Fabio L Janiszevski Date: Tue, 3 Mar 2020 13:22:35 -0300 Subject: [PATCH 2/2] Add reject to remove attributes from entry --- lib/i18n/backend/base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 285e5e61..698f2d5b 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -163,6 +163,7 @@ def resolve(locale, object, subject, options = EMPTY_HASH) # not standard with regards to the CLDR pluralization rules. # Other backends can implement more flexible or complex pluralization rules. def pluralize(locale, entry, count) + entry = entry.reject { |k, _v| k == :attributes } if entry.is_a?(Hash) return entry unless entry.is_a?(Hash) && count && entry.values.none? { |v| v.is_a?(Hash) } key = pluralization_key(entry, count)