React integration (i18next)
Check our i18next example application
For integration with React use standard React extension + we recommend also use ICU message formatter as that is supported on Tolgee platform natively:
- npm
- yarn
- pnpm
npm install react-i18next i18next-icu
yarn add react-i18next i18next-icu
pnpm install react-i18next i18next-icu
And then use following setup:
import { withTolgee, Tolgee, I18nextPlugin, DevTools } from '@tolgee/i18next';
import i18n from 'i18next';
import ICU from 'i18next-icu';
import { initReactI18next } from 'react-i18next';
const tolgee = Tolgee().use(DevTools()).use(I18nextPlugin()).init({
apiUrl: process.env.REACT_APP_TOLGEE_API_URL,
apiKey: process.env.REACT_APP_TOLGEE_API_KEY,
});
withTolgee(i18n, tolgee)
.use(ICU)
.use(initReactI18next)
.init({
lng: 'en', // or use i18next language detector
supportedLngs: ['cs', 'en', 'fr', 'de'],
});
Now you can use regular react-i18next.