Generate translated message files during the build and serve them from Server Components.
npm install -D @shipi18n/cliTranslate as part of the build script:
{
"scripts": {
"i18n": "shipi18n translate messages/en.json -t es,fr,de --incremental",
"build": "npm run i18n && next build"
}
}const messages = (await import(`../messages/${locale}.json`)).default// app/[locale]/layout.jsx
export default async function LocaleLayout({ children, params: { locale } }) {
const messages = (await import(`../../messages/${locale}.json`)).default
return (
<html lang={locale}>
<body>
<Provider messages={messages} locale={locale}>{children}</Provider>
</body>
</html>
)
}export function generateStaticParams() {
return ['en', 'es', 'fr', 'de'].map((locale) => ({ locale }))
}The translate step has not run for that language yet. Add it to -t and re-run npm run i18n.
Commit the generated files and use --incremental; unchanged keys are then skipped entirely.
Need help? Read the docs