Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #503 changes for Backend::Base #637

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def resolve(locale, object, subject, options = EMPTY_HASH)
# 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) }
return entry unless entry.is_a?(Hash) && count

key = pluralization_key(entry, count)
raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key)
Expand Down
17 changes: 17 additions & 0 deletions test/backend/pluralization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ def setup
assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :pirate)
end

test "Nested keys within pluralization context" do
store_translations(:xx,
:stars => {
one: "%{count} star",
other: "%{count} stars",
special: {
one: "%{count} special star",
other: "%{count} special stars",
}
}
)
assert_equal "1 star", I18n.t('stars', count: 1, :locale => :xx)
assert_equal "20 stars", I18n.t('stars', count: 20, :locale => :xx)
assert_equal "1 special star", I18n.t('stars.special', count: 1, :locale => :xx)
assert_equal "20 special stars", I18n.t('stars.special', count: 20, :locale => :xx)
end

test "Fallbacks can pick up rules from fallback locales, too" do
assert_equal @rule, I18n.backend.send(:pluralizer, :'xx-XX')
end
Expand Down
17 changes: 17 additions & 0 deletions test/backend/simple_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@ def setup
assert_equal true, I18n.backend.initialized?
end

test "Nested keys within pluralization context" do
store_translations(:en,
:stars => {
one: "%{count} star",
other: "%{count} stars",
special: {
one: "%{count} special star",
other: "%{count} special stars",
}
}
)
assert_equal "1 star", I18n.t('stars', count: 1, :locale => :en)
assert_equal "20 stars", I18n.t('stars', count: 20, :locale => :en)
assert_equal "1 special star", I18n.t('stars.special', count: 1, :locale => :en)
assert_equal "20 special stars", I18n.t('stars.special', count: 20, :locale => :en)
end

test "returns localized string given missing pluralization data" do
assert_equal 'baz', I18n.t('foo.bar', count: 1)
end
Expand Down