Installation (i18next)
To install Tolgee i18next integration library run:
- npm
- yarn
- pnpm
npm install @tolgee/i18next
yarn add @tolgee/i18next
pnpm install @tolgee/i18next
Then wrap your i18next instance withTolgee
:
import i18n from 'i18next';
import { withTolgee, Tolgee, I18nextPlugin, DevTools } from '@tolgee/i18next';
const tolgee = Tolgee()
.use(DevTools())
.use(I18nextPlugin())
.init({
// for development
apiUrl: ...,
apiKey: ...,
// for production
staticData: {
'en:translation': ...,
'cs:translation': ...
}
});
withTolgee(i18n, tolgee)
.use(...)
.init(...)
Now you can use regular i18next translation features.
i18next
namespaces are mapped to Tolgee namespaces and since i18next doesn't support empty namespace, you have to have your translations in some namespace in the Tolgee platform (i18next
defaults to "translation").
Language detection/changes
Tolgee will follow i18next configuration, so you can use i18next language detectors or set the language manually.
To change language use i18next.changeLanguage
function.
Preparing for production
In production mode, you should never use localization data from Tolgee REST API and never leak your API key. You should use data exported from the Tolgee platform. To get exported localization files, see exporting translations.
Then provide the data via Tolgee configuration options described in Providing static data.