Skip to main content
GatoJS translates the UI with next-intl. The locale is part of the URL, every feature keeps its own translation files, and the CLI generates the registry that loads them. Polish (pl) is the default and required locale; English (en) is enabled by default.

How it fits together

All pages live under the src/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").
Import Link, redirect, usePathname and useRouter from @/i18n/routing, not from next/navigation. These versions add the locale prefix for you, and usePathname returns the path without it. Take only notFound and useSearchParams from next/navigation.

How the locale is chosen

src/i18n/routing.ts
With 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:
  1. The prefix in the URL (/en/..., /pl/...).
  2. The NEXT_LOCALE cookie, if it holds a supported locale.
  3. The Accept-Language header: the first supported language wins, otherwise pl.
  4. The default locale, pl.
In practice this means:
  • With a browser set to English, unprefixed URLs redirect to /en/..., even right after npm run dev.
  • Visiting any /en/... page sets NEXT_LOCALE=en, so later unprefixed URLs redirect to English too.
  • Opening any /pl/... URL redirects to the unprefixed URL and sets NEXT_LOCALE=pl, which brings Polish back.
If you want unprefixed URLs to always render Polish, set 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
The rules 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: title in src/features/users/i18n/pl.json is users.title, not users.users.title.
  • Shallow merge. A feature can’t add to common or override a core message.
  • Valid names only. The namespace must match ^[a-z][a-zA-Z0-9-]*$. file-storage2 and myFeature pass; my_feature, Notes and 1x throw Nieprawidłowy klucz namespace i18n: <name> (“invalid i18n namespace key”).
  • No collisions. A name already taken by core (common, errors, sidebar, serviceMode) or another feature throws Kolizja namespace i18n: <name> (“i18n namespace collision”).
The merge runs on every page request, so an error here stops every page under 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.
Every message of the current locale is sent to the browser: NextIntlClientProvider is a client component, so its data ships with the page HTML, including on public pages such as /sign-in. Never put anything in a translation file that an anonymous visitor must not see.

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.
Keep feature strings in the feature’s namespace, even when they sound generic. Don’t add them to 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 the locales 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:
  1. Change locales in .wa/kit.json, for example to ["pl"] or back to ["pl", "en"].
  2. When enabling en, make sure src/app/messages/en.json and every feature’s i18n/en.json exist. Kit features ship with both files; add them to your own features.
  3. Regenerate and verify:
With ["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.
Don’t edit src/i18n/locales.generated.ts by hand. CI regenerates the files and fails on any diff (see CI workflows).

A third locale

Adding a locale such as de 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:

Email

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.