Add or Load Translations

There are a few options to load translations to your application instrumented by i18next. The most common approach to this adding a so called backend pluginarrow-up-right to i18next. The range of backends is large from loading translations in the browser using xhr/fetcharrow-up-right request to loading translations from databases or filesystemarrow-up-right in Node.jsarrow-up-right.

Add on init

You can add the translations on init

import i18next from 'i18next';

i18next
  .init({
    resources: {
      en: {
        namespace1: {
          key: 'hello from namespace 1'
        },
        namespace2: {
          key: 'hello from namespace 2'
        }
      },
      de: {
        namespace1: {
          key: 'hallo von namespace 1'
        },
        namespace2: {
          key: 'hallo von namespace 2'
        }  
      }
    }
  });

Add after init

You can add the translations after init

There are more options to adding, removing translations...learn more about resource handling.

circle-info

Please make sure to at least pass in an empty resources object on init. Else i18next will try to load translations and give you a warning that you are not using a backend.

Combined with a backend plugin

If you want to lazy load some translations via a backend plugin, you may need to use the partialBundledLanguages: true option. This allows some resources (or no resources) to be set on initialization while others can be loaded using a backend connector.

You may also want to set the ns option. To an empty array if you do not want to load any namespaces (also not the default namespace: 'translation') or to an array containing the namespaces to load.

Lazy load in memory translations

i18next-resources-to-backendarrow-up-right helps to transform resources to an i18next backend. This means, you can also lazy load translations, for example when using webpack:

Load using a backend plugin

Each plugin comes with a set of configuration settings like path to load resources from. Those settings are documented on the individual readme file of each repository.

Here is a sample using the i18next-http-backendarrow-up-right to load resources from the server.

triangle-exclamation
circle-info
circle-info

๐ŸŽ“ Check out this topic in the i18next crash course videoarrow-up-right.

Load using a smart backend pluginarrow-up-right serving directly from a CDNarrow-up-right

Just use the i18next-locize-backendarrow-up-right to load resources from the CDNarrow-up-right.

Herearrow-up-right you can find a step by step guide with a React.js app, which will unleash the full power of i18next in combination with locize. See how your developer experience with this localization workflow could look likearrow-up-right. There's also the possibility to have an even more focused developer experiencearrow-up-right, with the help of the autoutomatic translation workflowarrow-up-right and the use of the save missing keys functionality, new keys not only gets added to locize automatically, while developing the app, but are also automatically translatedarrow-up-right into the target languages using machine translation (like Google Translatearrow-up-right).

circle-check

locizearrow-up-right is the perfect translation management tool for your i18nextarrow-up-right project

Last updated