with one click
add-locale
// Adds a new language/locale to the application. Involves Strapi admin config, Next.js i18n routing, and translation files. Triggers: add language, add locale, new language, new translation, internationalization.
// Adds a new language/locale to the application. Involves Strapi admin config, Next.js i18n routing, and translation files. Triggers: add language, add locale, new language, new translation, internationalization.
| name | add-locale |
| description | Adds a new language/locale to the application. Involves Strapi admin config, Next.js i18n routing, and translation files. Triggers: add language, add locale, new language, new translation, internationalization. |
Add a new language/locale to the application. Involves Strapi admin config, Next.js i18n routing, and translation files.
Before proceeding, validate inputs:
de, fr, sk). Reject uppercase or invalid codes.German, French, Slovak).If invalid format provided, ask user to correct before proceeding.
Ask the user for:
de, fr, sk)German, French, Slovak)Copy apps/ui/locales/en.json to apps/ui/locales/{locale}.json.
The file structure must match en.json exactly โ same keys, translated values. Initially copy as-is and mark values for translation.
Existing locales for reference: en.json, cs.json.
Edit apps/ui/src/lib/navigation.ts.
Add the new locale code to the locales array:
export const routing = defineRouting({
locales: ["cs", "en", "{locale}"],
defaultLocale: "en",
localePrefix: "as-needed",
})
Keep the array sorted alphabetically.
The i18n config at apps/ui/src/lib/i18n.ts uses dynamic imports and automatically picks up new locale files:
messages: (
await (locale === "en"
? import("../../locales/en.json")
: import(`../../locales/${locale}.json`))
).default,
No changes needed unless you want HMR support for the new locale during development (currently only en has HMR via static import).
After the automated steps complete, inform the user:
The translation file and routing config are set up. You need to manually:
- Enable locale in Strapi: Go to Settings > Internationalization > Add new locale > select {locale}
- Translate content: For each content type with i18n enabled, switch to the new locale in Strapi admin and translate
[locale] route segment in apps/ui/src/app/[locale]/ handles locale routing automatically via next-intlgenerateStaticParams in the root layout iterates routing.locales โ new locale pages are generated automaticallylocalePrefix: "as-needed" setting means the default locale (en) has no prefix, all others get /{locale}/ prefix