Tolgee i18next integration
Tolgee i18next integration. For more information about Tolgee Toolkit, visit our documentation website
tolgee.io.
Installation
npm install i18next @tolgee/i18next
Usage
First, create a Tolgee instance and initialize it.
import i18next from 'i18next';
import { withTolgee } from "@tolgee/i18next";
withTolgee(i18n, { ... tolgee config ... })
.init({ ... i18next config ... })
This will:
- use add
tolgeeBackend
as backend plugin - use
tolgeeProcessor
for wrapping translations (with invivisible wrapperMode) - will call
tolgeeApply
on i18n instance to apply listeners and register tolgee (i18n.tolgee
) - will wrap
.init
function with custom function, which will use tolgeeOptions
to merge config with our custom config that is needed for in-context to work
We also recommend using ICU message format
, which is supported by Tolgee platform.
npm install i18next-icu
import ICU from 'i18next-icu';
withTolgee(i18n, ...)
.use(ICU)
.init(...)
Language changing
Tolgee will automatically switch language accordingly to i18next. So to get current language do:
const lang = i18n.lang;
To set language:
i18n.changeLanguage(lang);
To learn more, check Tolgee docs.