slim
slim copied to clipboard
Translator with #translate scoping
I am trying to use the translator plugin.
Is it possible to use h1 .my_key
instead of h1 my_controllers.my_action.my_key
?
This is possible using the ActionView Helper translate method that adds scoping on the key name, and help greatly to reduce duplication.
Thanks!
Try to put the classname inside ruby block like this h1 class="#{ruby code}"
that maybe call the ActionView Helper
Actually h1 .my_key
is not a css class, but should be recognized by the translator plugin as being h1 #{I18n.t '.my_key'}
.
You can find the plugin here for reference.
As this example: h1 Welcome to #{url}!
, h1 #{my_key}
doesn't work too?
If you read carefully the Readme, in the example actually what is translated is the string 'Welcome to %1!', and the url is passed as a parameter. The explanation is indeed lacking, and there is no example using I18n.
The idea of the translator plugin is to translate automatically, without having to call internationalization methods explicitly.
At least that's what I understand from reading the Readme.
Yes you are right, I'l need to work with a real case, do you have any repo I can clone?
I have not found many examples of the use of this plugin. I have not used it so far, because I was waiting on this issue.
I hope that the maintainers could chime in.
This issue hasn't been update for a while. Please let me know if it is still relevant for you. You can customize the tr_fn
option of Slim::Translator
with a custom translation function, which takes context into account. We could also offer such a function. See for example Slim::Translator.i18n_key
. Patches for this feature are welcome.