diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index d149081d..285e5e61 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -143,7 +143,7 @@ def resolve(locale, object, subject, options = EMPTY_HASH) result = catch(:exception) do case subject when Symbol - I18n.translate(subject, **options.merge(:locale => locale, :throw => true).except(:count)) + I18n.translate(subject, **options.merge(:locale => locale, :throw => true)) when Proc date_or_time = options.delete(:object) || object resolve(locale, object, subject.call(date_or_time, options)) @@ -163,7 +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) - return entry unless entry.is_a?(Hash) && count + return entry unless entry.is_a?(Hash) && count && entry.values.none? { |v| v.is_a?(Hash) } key = pluralization_key(entry, count) raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key) diff --git a/lib/i18n/backend/pluralization.rb b/lib/i18n/backend/pluralization.rb index a0a2f565..3bc45b10 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) and count + return entry unless entry.is_a?(Hash) && count && entry.values.none? { |v| v.is_a?(Hash) } pluralizer = pluralizer(locale) if pluralizer.respond_to?(:call) diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb index 8b3f1ad0..68e290ec 100644 --- a/test/backend/fallbacks_test.rb +++ b/test/backend/fallbacks_test.rb @@ -8,7 +8,7 @@ class Backend < I18n::Backend::Simple def setup super I18n.backend = Backend.new - store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en', :interpolate => 'Interpolate %{value}') + store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en', :interpolate => 'Interpolate %{value}', :interpolate_count => 'Interpolate %{value} %{count}') store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de') store_translations(:'de-DE', :baz => 'Baz in :de-DE') store_translations(:'pt-BR', :baz => 'Baz in :pt-BR') @@ -28,6 +28,10 @@ def setup assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE') end + test "keeps the count option when defaulting to a different key" do + assert_equal 'Interpolate 5 10', I18n.t(:non_existant, default: :interpolate_count, count: 10, value: 5) + end + test "returns the :de translation for a missing :'de-DE' when :default is a String" do assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => "Default Bar") assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => "Default Bar")