Technology

JavaScript localization:
A step-by-step introductory guide

The process of converting your JavaScript code to multiple languages during the internationalization of your project. I18N means designing software so it can handle multiple locales, languages, or regions.

There are a lot of possibilities out there, but we aim to cover the most practical approaches — from using an i18n library to automating translation work with a translation management platform.

This step-by-step guide helps you start your software localization project based on a JavaScript environment.

JavaScript localization (code example)

Prepare your app

Locize can be used with any i18n framework (or even with no i18n framework at all, e.g. via a simple script approach).

Example with i18next

Below we continue with i18next as i18n framework. If you're curious why we suggest i18next, have a look at this page.

To have multiple languages on your website or application with i18next, first install the dependencies. You can use the npm package, or load UMD/ESM/CJS builds from a CDN.

# npm
$ npm install i18next --save

# yarn
$ yarn add i18next
Localization in JavaScript (minimal example)

This example gives a quick overview of how localization in JavaScript can work and what functions are available in i18next. For production apps, follow the framework-specific integrations (React, Vue, Angular, Next.js, …).

import i18next from 'i18next';

i18next.init({
  lng: 'en',
  debug: true,
  resources: {
    en: {
      translation: {
        'key': 'hello world'
      }
    }
  }
}, (err, t) => {
  // initialized and ready to go!
  document.getElementById('output').innerHTML = i18next.t('key');
});

Check out the i18next getting started guide.

Already using i18next?

Then use i18next-locize-backend as your i18next backend.

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

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

Choose your framework

For famous JavaScript frameworks, Locize is easy to integrate through the JavaScript localization library i18next.

smart_display
i18next Crash Course | the JavaScript i18n framework
This video is hosted on YouTube. Accept YouTube cookies to watch it here.
Watch on YouTube
Framework resources

Checklist best practices

These questions help you decide on the best setup to internationalize with JavaScript.

  • For which JavaScript environment are you looking for an i18n solution?
  • Do you need a language detector for your environment?
  • Do you want to bundle the translations with your app?
  • Do you want to load the translations separate from your app via HTTP?
  • Do you want to manage your translations with a translation management system?

There is also a more detailed guide for first setup help directly at i18next (covers more than just JavaScript): supported frameworks guide.

Step-by-step code implementation (the manual way)

This checklist is based on implementing multiple languages for a sample React app.

For a more detailed walkthrough, see our tutorial: How to properly internationalize a React application using i18next.

  • Install i18next and the appropriate framework package
  • Install the browser language-detector
  • Prepare the i18next configuration
  • Translate content with hook / HOC / render prop
  • Create a language switcher
  • Add translations for other languages
  • Use pluralization and interpolation
  • Handle date & time formatting with interpolation
  • Use context for gender-specific translations
  • Separate translations from code (e.g. with i18next-locize-backend)

But there is more… For extensive projects, using just a library can be too inefficient.

Take a minute and read about automating this process below.

Automate translation work (the smart way)

Use the full power of i18next together with Locize to automate parts of the translation workflow.

smart_display
react-i18next and Locize (Translation Management for i18next)
This video is hosted on YouTube. Accept YouTube cookies to watch it here.
Watch on YouTube

Use the full power of the i18next library together with Locize, a localization management platform by the founders of i18next.

Register for free and unlock everything for a 14 day trial.

smart_display
react-i18next with automatic machine translation
This video is hosted on YouTube. Accept YouTube cookies to watch it here.
Watch on YouTube

The machine / generative AI translation feature enables every new content to get automatically translated into all other defined target languages.

Learn more about AI translation options.

Frequently asked questions

What is JavaScript localization?

Internationalization (i18n) prepares your JavaScript app to support multiple languages/locales. Localization (l10n) is about adapting content (texts, graphics, etc.) for a specific language/region.

How do I make my JavaScript app multilingual?

Choose an i18n framework (like i18next), instrument your code with translation keys, and follow the checklist in this guide.

What is i18n (internationalization)?

i18n is the process of preparing a software product for multiple markets by adding support for languages, locales and regional differences. Learn more in our guide: what is i18n.

How can I have multiple languages on my website?

Pick your JavaScript framework, install i18next, initialize it, then translate UI strings via t(). For website-focused tips, read website localization.

Why is i18next recommended for JavaScript localization?
  • Rich features (namespaces, interpolation, language detection plugins, …)
  • Maturity (battle-tested across many use cases)
  • Extensibility (works across React, Vue, Angular, Next.js, jQuery, and more)
Now it's your turn
Start your free 14-day trial and see how continuous localization feels in practice.