diff --git a/lib/i18n/backend/pluralization.rb b/lib/i18n/backend/pluralization.rb index 3bc45b10..b6026571 100644 --- a/lib/i18n/backend/pluralization.rb +++ b/lib/i18n/backend/pluralization.rb @@ -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) diff --git a/test/backend/pluralization_scope_test.rb b/test/backend/pluralization_scope_test.rb new file mode 100644 index 00000000..199aa493 --- /dev/null +++ b/test/backend/pluralization_scope_test.rb @@ -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