Repository navigation
Runtime locale layer: React / Next / Astro adapters - #17
Merged
Merged
Conversation
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.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.LocaleConfigis 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>(headlessrenderor 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; noastrodependency).Notes
reactentry leads with"use client"; thenextentry imports it by package name (external), so it isn't inlined into the server bundle.react/next/astroare optional peers.pnpm typecheck,pnpm build,pnpm test(150 pass, incl. 12 new core tests);dist/esm/react.jsleads with"use client";dist/esm/next.jsimportsrosetta-i18n/react.