pl) is the default and required locale; English (en) is enabled by default.
How it fits together
All pages live under thesrc/app/[locale]/ segment. For every request, src/i18n/request.ts loads the core messages and each feature’s messages for the resolved locale and merges them into one object. A namespace is a top-level key of that object: a client component asks for one with useTranslations("users"), a server component with await getTranslations("users").
How the locale is chosen
src/i18n/routing.ts
localePrefix: "as-needed", the default locale has no prefix: the Polish sign-in page is /sign-in, the English one is /en/sign-in. For an unprefixed URL the proxy rewrites internally to /pl/...; when the resolved locale is English it answers with a 307 redirect to the /en/... URL.
The routing config does not set localeDetection, so next-intl’s default (true) applies. The request locale is picked in this order:
- The prefix in the URL (
/en/...,/pl/...). - The
NEXT_LOCALEcookie, if it holds a supported locale. - The
Accept-Languageheader: the first supported language wins, otherwisepl. - The default locale,
pl.
- With a browser set to English, unprefixed URLs redirect to
/en/..., even right afternpm run dev. - Visiting any
/en/...page setsNEXT_LOCALE=en, so later unprefixed URLs redirect to English too. - Opening any
/pl/...URL redirects to the unprefixed URL and setsNEXT_LOCALE=pl, which brings Polish back.
localeDetection: false in defineRouting. next-intl then skips the cookie and the header. See Known limitations.
Namespaces and mergeMessages
The CLI generator writes one loader per feature and locale into moduleMessages in src/modules.generated.ts, with key equal to the feature’s directory name. request.ts merges them with the core file:
src/i18n/request.ts
mergeMessages enforces:
- One namespace per feature. A feature file lands as a whole under its directory name. Its top-level keys are already message keys:
titleinsrc/features/users/i18n/pl.jsonisusers.title, notusers.users.title. - Shallow merge. A feature can’t add to
commonor override a core message. - Valid names only. The namespace must match
^[a-z][a-zA-Z0-9-]*$.file-storage2andmyFeaturepass;my_feature,Notesand1xthrowNieprawidłowy klucz namespace i18n: <name>(“invalid i18n namespace key”). - No collisions. A name already taken by core (
common,errors,sidebar,serviceMode) or another feature throwsKolizja namespace i18n: <name>(“i18n namespace collision”).
src/app/[locale]/ from rendering. The sidebar looks labels up under <key>.<labelKey>, where key comes from the feature’s module.ts, so keep that key equal to the directory name. See Module registry.
Add a string
1
Add the key to both locale files
Add the key to
src/features/<name>/i18n/pl.json and to en.json in the same feature. Core keys use kebab-case, for example toast-invite-mail-failed. You can group keys into objects and read them with a dotted path, for example t(`role.${member.role}`).src/features/invoices/i18n/en.json
2
Use it in a component
Pass values through ICU placeholders in curly braces.
3
Regenerate only for new files
Run the generator only when a feature gets a new
i18n/<locale>.json file. The registry imports the file rather than copying its contents, so new keys in an existing file need no regeneration.src/app/messages/: those files belong to the core, and features don’t edit the core. If a string would help every project, propose it upstream (see Working with the kit).
A missing key doesn’t break rendering. next-intl logs a
MISSING_MESSAGE error through console.error and shows the key path, for example invoices.title. The same happens when a whole namespace is missing, for example when a feature has only pl.json and the page is opened in English. TypeScript doesn’t check message keys and no test compares pl.json with en.json, so you notice gaps on the page or in the console.Enable or disable a locale
The project’s locales live in thelocales field of .wa/kit.json. You choose them when creating the project (--locales, see gato create); without the field, the schema assumes ["pl", "en"]. The CLI accepts only pl and en, pl is required, and duplicates are rejected.
To switch English off or back on:
-
Change
localesin.wa/kit.json, for example to["pl"]or back to["pl", "en"]. -
When enabling
en, make suresrc/app/messages/en.jsonand every feature’si18n/en.jsonexist. Kit features ship with both files; add them to your own features. -
Regenerate and verify:
["pl"], the generator rewrites src/i18n/locales.generated.ts to ["pl"] as const and drops the en loaders from src/modules.generated.ts. The en.json files stay on disk, unused.
A third locale
Adding a locale such asde needs a change in the CLI itself. With only .wa/kit.json changed, gato generate exits with code 1 and a Zod error (Invalid option: expected one of "pl"|"en") and writes nothing. The locale list is hardcoded in the CLI’s manifest schema, argument parser, registry generator and kit sync command, so the change belongs in the kit repository. See Contributing.
Once the CLI accepts the locale, add it to locales, create src/app/messages/<code>.json with the common, errors, sidebar and serviceMode namespaces, add i18n/<code>.json to every feature, then run gato generate and npm run verify.
Text outside translation files
Some user-facing text does not go through next-intl. Keep this in mind before you promise a fully English UI:Related
Transports, templates and the mails the app sends.
Module registry
How the generator wires feature messages, env schemas and navigation.
Build a feature
Where a feature’s
i18n folder fits in its structure.gato generate
Regenerate the registry and locale files.