22

Any way to force the translation to a specific language only for some text. Something like:

t("my.text",:fr)

The reason is that i want the user to be able to change the language of their content but not the site interface. Thanks!

tronerta
  • 432
  • 6
  • 12
montrealmike
  • 11,433
  • 10
  • 64
  • 86

2 Answers2

60

It could be done this way:

I18n.t :foo, :locale => :fr

equivalent too:

t("my.text", :locale => :fr)
apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • Is there any way of the displayed translations automatically switching between languages without having to reload a page? So if I would change a page's language in Javascript, that it will show that using the Rails translation method. (Reloading the page is not possible in this case) – Jeroen May 03 '22 at 11:22
6
t("my.text", locale: :fr)

More options here

Michaël Witrant
  • 7,525
  • 40
  • 44