-
-
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
#translate modifies the passed argument hash #158
Comments
I don't get how adding options means the lookup fails, maybe I'm not understanding the issue correctly? |
The options hash will be modified. This by itself will cause any subsequent calls to behave unexpectedly. In the particular case, if you look at the fallback code in fallback.rb you will see that if there is a :fallback => true key, no additional fallback will be done. So after the first call options will now include :fallback => true and the presence of that will not trigger the fallback mechanism on the second call. So |
@tigrish the user has an options hash that they want to re-use for subsequent calls. because the first call modifies the options hash these are unexpected (and possibly problematic) side-effects. i agree that's an issue. can't we just duplicate the hash as soon it goes into |
OK thanks for the clarification. Referencing bug #124 even though they're different issues, I suspect there's some cross over. |
I18n.localize has the same issue. |
Fix #158: never modify the given options hash
The #translate method will modify the passed hash options, this results in very bad cases where a hash with interpolation values is passed to multiple #translate calls.
Not only valuable arguments can be lost, like :locale, but in case with fallback enabled, the
:fallback => true
key, will be introduces in the hash.That will be later passed to the next call to #translate that will incorrectly return a missing translation.
Here is an example with fallback configured to :en and missing :us translations:
Modifying the passed option hash is not expected behavior and a copy of it should be used instead.
The text was updated successfully, but these errors were encountered: