You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to translate a string with interpolated parameters where both the original string and a parameter are translated using sub-tag fallbacks.
This sounds contrived, but it can happen quite naturally in Rails applications, where I18n calls are hidden behind the Rails API. (For example when using model_name, human_attribute_name...)
Consider this:
<h1><%=t(:welcome,user: @customer)%></h1>
classCustomerdefto_sI18n.t(:customer)# Normally this would be 'model_name.human`endend
I18n.locale='de-DE'# not 'de'!
de: # not 'de-DE'!welcome: "Willkommen, %{user}!"customer: Kunde
What I expected to happen
I'd expect
I18n.t(:welcome,user: @customer)
to return
Willkommen, Kunde!
What actually happened
Instead it returns
Willkommen, translation missing: de-DE.customer
Versions of i18n, rails, and anything else you think is neccessary
This happens with version 0.8.1. The previous versions work as expected.
Note that Customer#to_s is called from inside the original translate callstack.
Before c913b0a the "fallback lock" was stored in the options hash. That was bad style, but it had the benefit that the flag was local and visible to the current execution stack only. Now the @fallback_locked variable leaks across different calls of translate.
If reverting to using options is out of the question, I believe an additional parameter will be necessary...
Closing this as #374 has now been merged. There will be a release done sometime in the next 24 hours which will include this change. Thank you @chadrschroeder + @daniel-rikowski :)
What I tried to do
I tried to translate a string with interpolated parameters where both the original string and a parameter are translated using sub-tag fallbacks.
This sounds contrived, but it can happen quite naturally in Rails applications, where I18n calls are hidden behind the Rails API. (For example when using
model_name
,human_attribute_name
...)Consider this:
What I expected to happen
I'd expect
to return
What actually happened
Instead it returns
Versions of i18n, rails, and anything else you think is neccessary
This happens with version 0.8.1. The previous versions work as expected.
I believe this is caused by c913b0a
Note that
Customer#to_s
is called from inside the originaltranslate
callstack.Before c913b0a the "fallback lock" was stored in the
options
hash. That was bad style, but it had the benefit that the flag was local and visible to the current execution stack only. Now the@fallback_locked
variable leaks across different calls oftranslate
.If reverting to using
options
is out of the question, I believe an additional parameter will be necessary...I created a runnable application: https://gist.github.com/daniel-rikowski/0dc50fe88b6d6f2309eaf33af16a6d92 (You need to save both files in the same directory)
The text was updated successfully, but these errors were encountered: