Skip to content

Commit

Permalink
Fix regression introduced by b7f69f7
Browse files Browse the repository at this point in the history
The count argument was being ignored in certain cases.

Fixes #510
  • Loading branch information
radar committed Jan 13, 2020
1 parent 91dee69 commit 1b5e345
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/backend/pluralization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Pluralization
# either pick a special :zero translation even for languages where the
# pluralizer does not return a :zero key.
def pluralize(locale, entry, count)
return entry unless entry.is_a?(Hash) && count && entry.values.none? { |v| v.is_a?(Hash) }
return entry unless entry.is_a?(Hash) && count

pluralizer = pluralizer(locale)
if pluralizer.respond_to?(:call)
Expand Down
55 changes: 55 additions & 0 deletions test/backend/pluralization_scope_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'test_helper'

class I18nBackendPluralizationScopeTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
include I18n::Backend::Fallbacks
end

def setup
super
I18n.default_locale = :'en'
I18n.backend = Backend.new

translations = {
i18n: {
plural: {
keys: [:one, :other],
rule: lambda { |n| n == 1 ? :one : :other },
}
},
activerecord: {
models: {
my_model: {
one: 'one model',
other: 'more models',
some_other_key: {
key: 'value'
}
}
}
}
}

store_translations('en', translations)
end

test "pluralization picks :other for 2" do
args = {
scope: [:activerecord, :models],
count: 2,
default: ["My model"]
}
assert_equal 'more models', I18n.translate(:my_model, args)
end

test "pluralization picks :one for 1" do
args = {
scope: [:activerecord, :models],
count: 1,
default: ["My model"]
}
assert_equal 'one model', I18n.translate(:my_model, args)
end

end

0 comments on commit 1b5e345

Please sign in to comment.