Skip to content

Runtime locale layer: React / Next / Astro adapters - #17

Merged
ian merged 2 commits into
mainfrom
feat/runtime-locale
Sep 28, 2026
Merged

ian merged 2 commits into
mainfrom
feat/runtime-locale

Conversation

@ian

@ian ian commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Pairs the translation engine with the missing runtime half: which locale is this request, and how do I switch — without hand-rolled middleware, server actions, and router.refresh() races.

Model

Resolution is deterministic and one-directional: URL prefix → forced header (x-rosetta-locale) → cookie → default. Switching writes the cookie and navigates to the localized URL, so the URL and cookie always agree; a full-page navigation is a single request with no refresh-after-push race.

LocaleConfig is plain data (no functions), so the same object crosses the server → client boundary.

Entries

  • rosetta-i18n/locale — core: resolveLocale, stripLocale, localizePath, switchHref, planSwitch, cookie helpers.
  • rosetta-i18n/react — LocaleProvider, useLocale, useLocales, useLocaleSwitch, useLocaleContext, <LocaleSwitcher> (headless render or a plain <select>).
  • rosetta-i18n/next — createLocaleMiddleware, <RosettaProvider> (server), getServerLocale, createSetLocaleAction. Re-exported alongside the existing translation helpers.
  • rosetta-i18n/astro — createAstroLocaleMiddleware, getAstroLocale (structural types; no astro dependency).

Notes

  • Client boundary preserved: the react entry leads with "use client"; the next entry imports it by package name (external), so it isn't inlined into the server bundle.
  • react/next/astro are optional peers.
  • Verified: pnpm typecheck, pnpm build, pnpm test (150 pass, incl. 12 new core tests); dist/esm/react.js leads with "use client"; dist/esm/next.js imports rosetta-i18n/react.
  • README: new "Locale routing & cookies" section.

Adds the runtime layer that pairs with the translation engine: a serializable
LocaleConfig, deterministic resolution (URL prefix > forced header > cookie >
default), and a switch that writes the cookie and navigates so the URL and cookie
always agree — no router.refresh() races.

- rosetta-i18n/locale  — framework-agnostic core (resolveLocale, stripLocale,
  localizePath, planSwitch, cookie helpers)
- rosetta-i18n/react   — LocaleProvider, useLocale/useLocaleSwitch, LocaleSwitcher
- rosetta-i18n/next    — createLocaleMiddleware, RosettaProvider, getServerLocale,
  createSetLocaleAction
- rosetta-i18n/astro   — createAstroLocaleMiddleware, getAstroLocale

Client boundary preserved (react entry leads with "use client"; next imports it by
package name). 12 new core tests.
@socket-security

socket-security Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​react@​19.3.01001007993100

View full report

@ian
ian merged commit 9fa712f into main Sep 28, 2026
8 checks passed
@ian
ian deleted the feat/runtime-locale branch September 28, 2026 02:48
@ian ian mentioned this pull request Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant