-
Notifications
You must be signed in to change notification settings - Fork 85
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
Interpolations? #162
Comments
Oh nice, I didn't actually know that Globalize could do this. This would be easy to implement as a plugin, so you could enable it with One problem is that Mobility already accepts and uses a hash of options passed ot the translation getter, e.g. |
Updated the wiki to mention this is not currently supported. |
I suppose something like: record.greeting(interpolate: { name: 'Chris' }) would work. |
This API makes sense. I would prefer |
I don't see a need for this to be part of mobility, as String already supports interpolation via the % method: "Hello, %{name}!" % { name: "Chris"} # => "Hello, Chris!" So you should be able to use it to get the desired result: record.greeting % {name: 'Chris'} # => "Hello, Chris!" As an alternative, looking at globalize's implementation, it just seems to be doing some argument checking and then calling I18n.interpolate(record.greeting, name: 'Chris') # => "Hello, Chris!" I didn't look into the details of what the difference between |
@pwim I18n interpolation is not as naive as Globalize does call |
Here is the implementation in I18n. |
@shioyama That's not all of it, another important part is this optimization: Nevermind, that doesn't look useful for Mobility |
Manually calling |
It's true that the difference between: I18n.interpolate(record.greeting, name: 'Chris') and record.greeting(interpolate: { name: 'Chris' }) is pretty small, if that's all the plugin would do. It's also more obvious what is going on in the first case. |
I'm going to close this, it doesn't seem like a killer feature. If anybody things otherwise, please feel free to comment. |
For example, consider a model with a translated
greeting
attribute with value such asHello, %{name}!
.with Globalize, the following works:
with Mobility, interpolation is not performed.
I've tried migrating from globalize as per the wiki article.
The text was updated successfully, but these errors were encountered: