i18next documentation
🏠 i18next🌐 localization as a service🎓 i18next crash course💾 GitHub Repository
  • Introduction
  • Overview
    • Getting started
    • Comparison to others
    • API
    • Configuration Options
    • Supported Frameworks
    • Plugins and Utils
    • For Enterprises
    • First setup help
    • TypeScript
  • Translation Function
    • Essentials
    • Interpolation
    • Formatting
    • Plurals
    • Nesting
    • Context
    • Objects and Arrays
  • Principles
    • Best Practices
    • Translation Resolution
    • Namespaces
    • Fallback
    • Plugins
  • How to
    • Add or Load Translations
    • Extracting translations
    • Caching
    • Backend Fallback
    • FAQ
  • Misc
    • JSON Format
    • Creating own Plugins
    • Migration Guide
    • The history of i18next
    • Testimonials
  • 🌐localization as a service
  • 🎓i18next crash course
  • 💾GitHub Repository
Powered by GitBook
On this page
  • Add on init
  • Add after init
  • Combined with a backend plugin
  • Lazy load in memory translations
  • Load using a backend plugin
  • Load using a smart backend plugin serving directly from a CDN
  1. How to

Add or Load Translations

Last updated 1 month ago

There are a few options to load translations to your application instrumented by i18next. The most common approach to this adding a so called to i18next. The range of backends is large from loading translations in the browser using request to loading translations from databases or in .

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

import i18next from 'i18next';

i18next.init({ resources: {} });
i18next.addResourceBundle('en', 'namespace1', {
  key: 'hello from namespace 1'
});

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.

import i18next from 'i18next';

i18next.init({
  partialBundledLanguages: true,
  ns: [],
  resources: {}
});
i18next.addResourceBundle('en', 'namespace1', {
  key: 'hello from namespace 1'
});
// or via backend
// i18next.loadNamespaces(['myNamespace1', 'myNamespace2'])
// i18next.loadLanguages(['de', 'fr'])
// etc.

Lazy load in memory translations

import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';

i18next
  .use(resourcesToBackend((language, namespace) => import(`./locales/${language}/${namespace}.json`)))
  .init({ /* other options */ })

Load using a backend plugin

import i18next from 'i18next';
import Backend from 'i18next-http-backend';

i18next
  .use(Backend)
  .init({
    backend: {
      // for all available options read the backend's repository readme file
      loadPath: '/locales/{{lng}}/{{ns}}.json'
    }
  });
import i18next from 'i18next';
import Backend from 'i18next-locize-backend';

i18next
  .use(Backend)
  .init({
    backend: {
      projectId: '[PROJECT_ID]',
      apiKey: '[API_KEY]',
      referenceLng: '[LNG]'
    }
  });

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

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 : 'translation') or to an array containing the namespaces to load.

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

Each 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 to load resources from the server.

Having a combination of + will not implicitly take one or the other source as fallback resources. If you need some fallback behaviour you may use the . A short example can be found . With you can also create some .

🎓 Check out this topic in the .

Load using a serving directly from a

Just use the to load resources from the .

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 . There's also the possibility to have an , with the help of the 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 into the target languages using machine translation (like ).

Check out to learn more about how you can use generative AI together with i18next.

is the perfect translation management tool for your project

➡️ + =

backend plugin
xhr/fetch
filesystem
Node.js
resource handling
i18next-resources-to-backend
plugin
i18next-http-backend
What's a plugin?
i18next crash course video
smart backend plugin
CDN
i18next-locize-backend
CDN
Here
could look like
even more focused developer experience
autoutomatic translation workflow
automatically translated
Google Translate
this blog post
locize
i18next
i18next
locize
true continuous localization
i18next-chained-backend
here
i18next-chained-backend
caching behaviour
defining resources
having a backend
default namespace