Directly indicate in which language to translate

I, as usual, have my translation files in locales.

Now I have an invitation in different languages.

I want the user to choose in which language mail should be sent, because this is not about the language of the working user, but about the language that the mail recipient should read.

Is there a way to explicitly specify the rails, which language to choose, for example t(:my_string, :en) ?

The goal is to temporarily translate it for only one call t .

This is what I need to specify in the t() command which language to use.

Thanks.

Yours, joern.

+6
source share
3 answers

It is possible to pass the :locale option to the t method:

  t :my_string, locale: :de 
+6
source

I think you clearly need to set the correct language for I18n.
You can use: I18n.locale = :en to set the language you need.

See also here: I18n

+3
source

You can use the I18n backend, which takes a locale as the first argument:

I18n.backend.translate(:en, :my_string)

0
source

Source: https://habr.com/ru/post/896036/


All Articles