A
A
Anton Isaev2016-07-03 19:14:31
Ruby on Rails
Anton Isaev, 2016-07-03 19:14:31

How to use two languages ​​in the application at the same time?

Good afternoon! The question is: can I use 2 language files at the same time in one application using I18n.t?
Let me explain with an example: there is a locale RU (set "by default") and there is a locale EN (optional). There is, for example, the following line in the code: This line will pull out the string 'ru.hello_world' from the RU locale. But hypothetically, a situation may arise that there will be no hello_world line in the file with the RU locale. In this case, as a solution for myself, I see loading the missing lines from the EN locale. Those. the logic of the program: if there is no string in the RU locale, then I load the string from the EN locale. Is it possible to do so? Unfortunately, if you use the following code:
$s = I18n.t('hello_world')


$s = I18n.t('hello_world', :default=>I18n.t('en.hello_world'))
then if there is no string in RU, an attempt is made to load the string 'ru.en.hello_world' from the RU locale.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Demidenko, 2016-07-03
@antooninc

You need config.i18n.fallbacks
In production it is installed automatically:

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question