-
-
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
Translations returned as hash when model-inflection has nested keys #514
Comments
The latest release of i18n is 1.8.2 and contains a fix for this issue: https://github.com/ruby-i18n/i18n/releases/tag/v1.8.2. You’re saying you’re using 1.8.1. |
@radar sounds good. Would you say that the pattern of nesting attributes within a key meant for inflection is bad? |
Likely yes. It shouldn’t effect the performance of the library. It’s hash-based, so it’s only picking out the relevant keys as you need them. It’ll ignore other keys. |
That's kind of what I'm wondering...it may have been a regression, but if it forces better patterns, I'm for it. 👍 ❤️ |
@radar can confirm this still caused the same issues in 1.8.2. |
I am unable to reproduce this in a new Rails application. Please provide an application that reliably reproduces the issue with any version of Rails, and I18n 1.8.2. |
@chevinbrown Unfortunately, there is still in error in 1.8.2 When you use the following locale file content: en:
model:
one: Single
other: Multiple
nested:
broken: Broken Then you see the following situation: > I18n.t('model', count: 1)
{:one=>"Single", :other=>"Multiple", :nested=>{:broken=>"Broken"}} When there is no nested information, so the en:
model:
one: Single
other: Multiple > I18n.t('model', count: 1)
Multiple Do you want to have another issue for this? |
It’s a simple request, really. |
This application is clearly using 1.8.1: https://github.com/mobilutz/ruby-i18n-issue-514/blob/master/Gemfile.lock#L67. Please upgrade to 1.8.2.
|
I will push I18n upgrade as well.
|
I am able to reproduce this issue in 1.8.2, however I know of the fix. The issue lies here: https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/backend/pluralization.rb#L34 When this line attempts to find the pluralizer logic in your application, the translation is missing and so this returns a String:
I18n by default does not include pluralization rules because there are way too many languages, and not every application needs pluralization rules for every language. To define the pluralization rules, we have a separate gem called |
@radar Thanks for that information. I will definately add the additional gem to our app, to see if that solves the problem. Can you maybe enlighten me, why version 1.7.1 (a patch version) lead to this error? |
Check out the changelog: https://github.com/ruby-i18n/i18n/releases/tag/v1.7.1 Count issue was introduced in 1.7.0 and to PATCH that issue I released 1.7.1. I don’t see a problem here. |
This issue still exists in cases where the user is not using The issue was introduced in #503 in both |
Reproducing test case (add it to test "simple backend translate: 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)
end
|
Pre 1.7.1 State
Related: #510
Our translations look something like:
What I expected to happen
Moose.model_name.human(count: 2) #=> 'Moosen'
What actually happened
Moose.model_name.human(count: 2) #=> Hash
(Actually, I think this makes more sense!)
Versions of i18n, rails, and anything else you think is necessary
So, it seems that our application wasn't really using model-translations idiomatically. The usage are not attributes, so they kinda got shoved in below the model-key.
If that pattern is considered wrong, this is a good forcing function towards convention (maybe it can be added to docs?). If it's an acceptable pattern, I would consider this a regression.
Happy to provide more detail/insight if required, but this seems pretty straightforward.
The text was updated successfully, but these errors were encountered: