Skip to content

I18n

Chrome DocsFirefox Docs

This page discusses how to setup internationalization using the vanilla browser.i18n APIs and mentions some alternatives if you want to use something else.

Usage

  1. Add default_locale to your manifest:

    ts
    export default defineConfig({
      manifest: {
        default_locale: 'en',
      },
    });
  2. Create messages.json files in the public/ directory:

    html
    📂 {srcDir}/
       📂 public/
          📂 _locales/
             📂 en/
                📄 messages.json
             📂 de/
                📄 messages.json
             📂 ko/
                📄 messages.json
    jsonc
    // public/_locales/en/messages.json
    {
      "helloWorld": {
        "message": "Hello world!",
      },
    }
  3. Get the translation:

    ts
    browser.i18n.getMessage('helloWorld');
  4. Optional: Add translations for extension name and description:

json
{
  "extName": {
    "message": "..."
  },
  "extDescription": {
    "message": "..."
  },
  "helloWorld": {
    "message": "Hello world!"
  }
}
ts
export default defineConfig({
  manifest: {
    name: '__MSG_extName__',
    description: '__MSG_extDescription__',
    default_locale: 'en',
  },
});

Alternatives

The vanilla API has very few features, which is why you may want to consider using third-party NPM packages like i18next, react-i18n, vue-i18n, etc.

However, it is recommended you stick with the vanilla API (or a package based on top of the vanilla API, like @wxt-dev/i18n), because:

  • They can localize text in your manifest and CSS files
  • Translations are loaded synchronously
  • Translations are not bundled multiple times, keeping your extension small
  • Zero configuration

Here are some examples of how to setup a third party i18n library: