I18next: translate for a specific language

Created on 25 Aug 2017  路  3Comments  路  Source: i18next/i18next

does i18next allow you to translate a key for a specific language? Sometimes the case arises when I need to display the same translated string in multiple languages, and it seems like i18next doesn't yet support that. Can anyone point me to documentation for it? or, if this is not yet a feature, should it be added?

Most helpful comment

I had the same question. Just found out that you simply need to load the language first.

  1. make sure the language's json is available

    • preload the language in init, OR

       i18next.init({ preload: ['de'] });

- load the language after initialization.  

      i18next.loadLanguages(['de']);
  1. translate for a specific language

    i18next.t'('key', { lng: 'de' });

All 3 comments

not sure what you mean, but guessing:

i18next.t('key', { lng: 'en' });
i18next.t('key', { lng: 'de' });

I had the same question. Just found out that you simply need to load the language first.

  1. make sure the language's json is available

    • preload the language in init, OR

       i18next.init({ preload: ['de'] });

- load the language after initialization.  

      i18next.loadLanguages(['de']);
  1. translate for a specific language

    i18next.t'('key', { lng: 'de' });

confirmed that preloading the languages solves it. thanks

Was this page helpful?
0 / 5 - 0 ratings