slim icon indicating copy to clipboard operation
slim copied to clipboard

Translator with #translate scoping

Open NicolasWebDev opened this issue 7 years ago • 6 comments

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!

NicolasWebDev avatar Sep 06 '16 20:09 NicolasWebDev

Try to put the classname inside ruby block like this h1 class="#{ruby code}" that maybe call the ActionView Helper

josueadelima avatar Apr 06 '17 05:04 josueadelima

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.

NicolasWebDev avatar Apr 07 '17 23:04 NicolasWebDev

As this example: h1 Welcome to #{url}!, h1 #{my_key} doesn't work too?

josueadelima avatar Apr 07 '17 23:04 josueadelima

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.

NicolasWebDev avatar Apr 07 '17 23:04 NicolasWebDev

Yes you are right, I'l need to work with a real case, do you have any repo I can clone?

josueadelima avatar Apr 08 '17 00:04 josueadelima

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.

NicolasWebDev avatar Apr 09 '17 00:04 NicolasWebDev

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.

minad avatar Sep 18 '23 12:09 minad