Translate your locale files at build time, then read them with react-i18next as usual.
npm install -D @shipi18n/cli
npm install react-i18next i18nextAdd a script that translates your source locale before the build. The key lives in your shell or CI secrets — it is never bundled, because this step runs before the bundler does.
{
"scripts": {
"i18n": "shipi18n translate src/locales/en.json -t es,fr,de --incremental",
"build": "npm run i18n && vite build"
}
}const { t } = useTranslation(); return <p>{t('greeting', { name })}</p>import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import en from './locales/en.json'
import es from './locales/es.json'
import fr from './locales/fr.json'
i18n.use(initReactI18next).init({
resources: { en: { translation: en }, es: { translation: es }, fr: { translation: fr } },
lng: 'en',
fallbackLng: 'en',
interpolation: { escapeValue: false },
})// en.json { "greeting": "Hello, {{name}}!" }
// es.json { "greeting": "¡Hola, {{name}}!" }
function Welcome({ name }) {
const { t } = useTranslation()
return <p>{t('greeting', { name })}</p>
}Check that the npm run i18n step ran before the build and that the generated files are imported in your i18n init.
i18next falls back to the key when it is missing. Re-run the translate step; the key was probably added after the last run.
Need help? Read the docs