Installation
With WXT
Install
@wxt-dev/i18n
via your package manager:shpnpm i @wxt-dev/i18n
Add the WXT module to your
wxt.config.ts
file and setup a default locale:tsexport default defineConfig({ modules: ['@wxt-dev/i18n/module'], manifest: { default_locale: 'en', }, });
Create a localization file at
<srcDir>/locales/<default_locale>.yml
or move your existing localization files there.yml# <srcDir>/locales/en.yml helloWorld: Hello world!
TIP
@wxt-dev/i18n
supports the standard messages format, so if you already have localization files at<srcDir>/public/_locale/<lang>/messages.json
, you don't need to convert them to YAML or refactor them - just move them to<srcDir>/locales/<lang>.json
and they'll just work out of the box!To get a translation, use the auto-imported
i18n
object or import it manually:tsimport { i18n } from '#i18n'; i18n.t('helloWorld'); // "Hello world!"
And you're done! Using WXT, you get type-safety out of the box.
Without WXT
Install
@wxt-dev/i18n
via your package manager:shpnpm i @wxt-dev/i18n
Create a messages file at
_locales/<lang>/messages.json
or move your existing translations there:json{ "helloWorld": { "message": "Hello world!" } }
INFO
For the best DX, you should to integrate
@wxt-dev/i18n
into your build process. This enables:- Plural forms
- Simple messages file format
- Type safety
See Build Integrations to set it up.
Create the
i18n
object, export it, and use it wherever you want!tsimport { createI18n } from '@wxt-dev/i18n'; export const i18n = createI18n(); i18n.t('helloWorld'); // "Hello world!";