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

Translation using sub-tags and fallbacks broken since 0.8.1 #366

Closed
daniel-rikowski opened this issue May 7, 2017 · 2 comments
Closed

Comments

@daniel-rikowski
Copy link

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:

<h1><%= t(:welcome, user: @customer) %></h1>
class Customer
  def to_s
    I18n.t(:customer) # Normally this would be 'model_name.human`
  end
end
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.

I believe this is caused by c913b0a

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...


I created a runnable application: https://gist.github.com/daniel-rikowski/0dc50fe88b6d6f2309eaf33af16a6d92 (You need to save both files in the same directory)

@chadrschroeder
Copy link

This will be fixed by #374.

@radar
Copy link
Collaborator

radar commented Jul 6, 2017

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 :)

@radar radar closed this as completed Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants