Skip to content

React Integration

NPM Package Version

React integration for tanzlate, including components interpolation.

Installation

bash
npm install @tanzlate/react
bash
yarn add @tanzlate/react
bash
pnpm add @tanzlate/react

Usage

<I18nProvider>

The I18nProvider is a React context provider that:

  • Initializes an i18next instance with the given config.
  • Exposes the i18n context via React's createContext/useContext.
  • Bridges language-change events into React state so components re-render automatically.
tsx
import { I18nProvider } from '@tanzlate/react';

export default function App() {
  return (
    <I18nProvider config={i18nConfig}>
      <MyApp />
    </I18nProvider>
  );
}

useI18n

ts
import { useI18n } from '@tanzlate/react';

const { cT, globalT, forNamespace, lang, changeLanguage } = useI18n('my_namespace');
Return valueTypeDescription
cTcTFuncTranslation helper scoped to the given namespace
globalTcTFuncTranslation helper for the global namespace
forNamespace(ns) => cTFuncFactory to create a helper for any namespace
langstringCurrent language
changeLanguage(lng) => Promise<void>Change the active language