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 scaffolds next-intl integration automatically:
npx translate-kit initIn keys mode, the wizard:
- Installs next-intl automatically
- 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"
}
}Type Safety
Enable typeSafe: true in your config to auto-generate a next-intl.d.ts file on every scan. This gives you autocomplete and compile-time validation for all message keys.
export default defineConfig({
// ...
typeSafe: true,
});You can also generate types manually at any time with translate-kit typegen.
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 runto scan, transform, and translate in one step - On subsequent changes, run
translate-kit runto update only what changed
You can also run each step individually:
translate-kit scan— extract strings and generate keystranslate-kit codegen— replace strings witht()callstranslate-kit translate— generate translations
If you only edit source message JSON files manually (without changing source code), translate-kit translate is all you need.