next-intl Integration
Using translate-kit with next-intl.
translate-kit is designed to work seamlessly with next-intl. The generated message files are directly compatible with useTranslations.
Setup
The init command can scaffold next-intl integration automatically:
npx translate-kit initWhen you select next-intl as your i18n library, the wizard creates:
i18n/request.tswith locale detection- Updates
next.config.tswithcreateNextIntlPlugin
Message Format
translate-kit generates nested JSON files that next-intl expects:
{
"common": {
"save": "Guardar",
"cancel": "Cancelar"
},
"auth": {
"login": "Iniciar sesion",
"signup": "Registrarse"
}
}Using with the Scanner
When scan.i18nImport is set to "next-intl" (the default), the codegen step:
- Adds
import { useTranslations } from "next-intl"to components - Injects
const t = useTranslations()in component bodies - Replaces hardcoded strings with
{t("key")}calls
Before
function Hero() {
return (
<div>
<h1>Welcome to our platform</h1>
<p>Get started today</p>
</div>
);
}After
import { useTranslations } from "next-intl";
function Hero() {
const t = useTranslations();
return (
<div>
<h1>{t("hero.welcome")}</h1>
<p>{t("hero.getStarted")}</p>
</div>
);
}Workflow
A typical next-intl + translate-kit workflow:
- Write components with hardcoded English strings
- Run
translate-kit scanto extract strings and generate keys - Run
translate-kit codegento replace strings witht()calls - Run
translate-kit translateto generate translations - On subsequent changes, run
translate-kit translateto update only what changed