← ClaudeAtlas

nextjs-locale-monorepolisted

Add locale-prefixed i18n routing across a Next.js monorepo (Turborepo / pnpm workspaces) by extracting the engine into a shared workspace package that every app consumes — locale detection + a middleware/proxy factory + a `use client` LocaleProvider/hooks, plus a shared supportedLanguages config. Each app redirects `/` and unprefixed paths to `/<locale>/…` from the toggle's last choice (the NEXT_LOCALE cookie) then the browser's Accept-Language, wiring only a thin middleware + `[locale]` layout. Use when several apps in one repo need consistent `/en-hk/…` `/zh-hk/…` routing, sharing locale logic via a workspace package instead of copy-paste, dual ESM/CJS build of a package that ships a client provider, Turbo build-ordering so the lib builds before the apps, or per-app locale wiring. For a single standalone site, use nextjs-locale-standalone instead.
stealth-engine/skills · ★ 2 · Web & Frontend · score 76
Install: claude install-skill stealth-engine/skills
# Next.js locale routing — monorepo (shared package) The same locale-routing behaviour as **nextjs-locale-standalone**, but the engine lives in one workspace package (`i18n-routing`) that every app imports, so detection, the cookie name, and the provider/hooks stay identical across apps. Read that sibling skill for the behaviour spec; this skill is about the **package + wiring**. Copy-paste files are in [`templates/`](./templates). ## The behaviour (shared with the standalone skill) Unprefixed requests 307-redirect to `/<locale>/…`, locale chosen by priority: **`NEXT_LOCALE` cookie (toggle's last choice) → `Accept-Language` (browser) → default**. The redirect carries `Vary: Accept-Language, Cookie` (its locale was negotiated from them); prefixed paths pass through with `x-locale` + the `NEXT_LOCALE` cookie stamped but **no** such `Vary` (their locale is fixed by the URL, so it'd only fragment the cache). The LocaleToggle navigates to `/<newLocale>/…`; the middleware is the single writer of the cookie, so the choice persists. The `NEXT_LOCALE` cookie defaults to **`httpOnly: true`** — it's read server-side (`request.cookies`) only, never from client JS, so keep it out of reach of injected scripts. Set `httpOnly: false` only if client JS genuinely must read it. It also defaults to a **1-year `maxAge`** (`defaultCookieOptions` in `templates/package/src/config.ts`) so the toggle's choice survives a browser restart — without it the cookie is session-only and the "choice persist