Skip to content

Commit

Permalink
Merge pull request #519 from fabiosammy/fix-pluralize-on-unknown-loca…
Browse files Browse the repository at this point in the history
…le-with-attributes

Fix pluralize on unknown locale with attributes
  • Loading branch information
radar committed Jun 4, 2020
2 parents 4e9bd53 + 572bca8 commit a8f4fdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/backend/pluralization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8f4fdc

Please sign in to comment.