-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Preserve count option #503
Conversation
d5c5552
to
9a5ae3e
Compare
lib/i18n/backend/base.rb
Outdated
@@ -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.select{|v| v.is_a?(Hash)}.size == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps:
entry.values.none? { |v| v.is_a?(Hash) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To help with archeology:
This implicitly changed the behaviour of pluralization contexts with nested hashes:
en:
stars:
one: "%{count} star"
other: "%{count} stars"
special:
one: "%{count} special star"
other: "%{count} special stars"
Before:
> I18n.t("stars", count: 1)
"1 star"
After:
> I18n.t("stars", count: 1)
{:one=>"one", :other=>"other", :special=>{:one=>"one special star", :other=>"other special star"}}
Which was reported as #510, and was reverted in the case of Backend::Pluralization
in 1b5e345, but not Backend::Base
. The Backend::Base
was reported as #514.
9a5ae3e
to
ffaf7f0
Compare
Could you please add a test to this PR to ensure that the behaviour doesn't get re-broken later on? |
Which test file would be most suitable for this in your opinion? |
I figured Thanks again! I'll do a release a little later on today (within an hour or two). Sorry for the trouble caused by #480 and thanks for your patience! |
I had a translation file with an extra hash inside
|
This change in I18n ruby-i18n/i18n#503 breaks our lookup for one/many when there is also a nested hash. `Account.model_name.human` was returning the hash `{:one=>"Payment Source", :other=>"Payment Sources", :owner=>"Owner", :statuses=>{:active=>"Active", :suspended=>"Suspended"}}`. Cleaning this up seemed simpler than trying to dig in to I18n.
This change in I18n ruby-i18n/i18n#503 breaks our lookup for one/many when there is also a nested hash. `Account.model_name.human` was returning the hash `{:one=>"Payment Source", :other=>"Payment Sources", :owner=>"Owner", :statuses=>{:active=>"Active", :suspended=>"Suspended"}}`. Cleaning this up seemed simpler than trying to dig in to I18n.
This change in I18n ruby-i18n/i18n#503 breaks our lookup for one/many when there is also a nested hash. `Account.model_name.human` was returning the hash `{:one=>"Payment Source", :other=>"Payment Sources", :owner=>"Owner", :statuses=>{:active=>"Active", :suspended=>"Suspended"}}`. Cleaning this up seemed simpler than trying to dig in to I18n.
This change in I18n ruby-i18n/i18n#503 breaks our lookup for one/many when there is also a nested hash. `Account.model_name.human` was returning the hash `{:one=>"Payment Source", :other=>"Payment Sources", :owner=>"Owner", :statuses=>{:active=>"Active", :suspended=>"Suspended"}}`. Cleaning this up seemed simpler than trying to dig in to I18n.
This change in I18n ruby-i18n/i18n#503 breaks our lookup for one/many when there is also a nested hash. `Account.model_name.human` was returning the hash `{:one=>"Payment Source", :other=>"Payment Sources", :owner=>"Owner", :statuses=>{:active=>"Active", :suspended=>"Suspended"}}`. Cleaning this up seemed simpler than trying to dig in to I18n.
This change in I18n ruby-i18n/i18n#503 breaks our lookup for one/many when there is also a nested hash. `Account.model_name.human` was returning the hash `{:one=>"Payment Source", :other=>"Payment Sources", :owner=>"Owner", :statuses=>{:active=>"Active", :suspended=>"Suspended"}}`. Cleaning this up seemed simpler than trying to dig in to I18n.
See ruby-i18n#635 for discussion
See ruby-i18n#635 for discussion
…on_with_base_backend Revert #503 changes for `Backend::Base`
Some rails validation messages are broken after applying PR #480
More info in comment of #480