Skip to content

feat(i18n): take the language set from SahajCloud, not from supportedLanguages - #168

Closed
Ardnived wants to merge 7 commits into
mainfrom
feat/cms-language-set
Closed

Ardnived wants to merge 7 commits into
mainfrom
feat/cms-language-set

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • The languages the widget offers are now an operator's decision, read from languages on SahajCloud's sy-atlas-config global (feat(api): serve SEO metadata for an atlas route (C3) — blocks the WordPress plugin and WeMeditateWeb SSR SahajCloud#645) instead of a build-time constant. The picker renders that set, and a language the operator has switched off is corrected rather than rendered — so the widget can no longer offer a language SahajCloud publishes no hreflang for.
  • Nothing changes for an atlas nobody has touched. The CMS defaults to the same ten, and every way the read can fail — a global with no such field, a key not granted it, a dead request — lands on the bundles this build ships, which is exactly what the picker offered before.
  • No new origin, no CSP change, no boot cost. One small read of the API hosts already allow, warmed alongside the clients/me read the widget already blocks on.

The split, and why supportedLngs is not part of it

The old constant answered two questions that turned out to have different owners.

Owner
shippedLanguages this build which bundles exist in public/locales/ — still pinned by an exact-equality spec
offeredLanguages() the operator, narrowed by us shipped ∩ enabled — what the picker renders and what the language may be

i18next's supportedLngs deliberately stays the shipped set. Its job is "never fetch a bundle that does not exist", which is a fact about this build — driven from the CMS, a language enabled before we ship it becomes two guaranteed 404s and an English interface under lang="it", the exact promise the ticket says we cannot keep. It also cannot be narrowed later: i18next's LanguageUtil copies it in its constructor, so post-init narrowing means writing to services.languageUtils. The security review independently found a second reason to keep it: it is what stops any untrusted code reaching the unencoded ${VITE_HOST}/locales/${lng}/${ns}.json template.

⚠ This is the one place the implementation departs from the ticket's literal wording (item 2 asks for supportedLngs to come from the CMS). The operator's set is applied where it can be applied honestly instead: the picker's rows, and the language the widget resolves to.

Boot order — measured, not assumed

The ticket asked for this to be decided, and noted a delayed first paint is a cost the host pays. Initialize with the shipped bundles, narrow once the config arrives — with the read warmed in parallel with the clients/me read the tree already suspends on.

measured
Query routing clients/me 403→1906 ms, config 455→1907 ms — fully overlapped
Path routing clients/me 211→978 ms, config 225→275 ms — settled 703 ms early
Warmed (shipped behaviour) interface paints once, in English; <html lang> never leaves en
Same response held back 3 s paints German at 3.9 s, flips to English at 5.4 s

That last row is why the warm is load-bearing rather than decorative. Path routing needed its own call (PathBoot): it reads clients/me above App, so App's mount effect fires a round trip too late.

shipped ⊇ enabled, off the network

A language enabled with no bundle here is invisible at runtime: nothing errors, the viewer just gets English while SahajCloud's hreflang says that language has a page. scripts/atlas-languages.json is a committed snapshot (pnpm sync:atlas-languages [--write]) that the unit lane asserts against — the sync:atlas-contract shape the ticket named, keeping the lane off the network. The script reports the same finding itself against the live set, so you learn it on the run that fetched.

⚠ It does not catch an operator acting after the last sync — syncedAt is in the file so that gap is visible rather than assumed, and the runtime survives it by construction: offeredLanguages drops what it cannot render.

Verification

  • Lint ✓ · Types ✓ · Tests ✓ 1376 passing · Build ✓ · Ladle ✓
  • Size ✓ standalone 300.2/310, loader 2.9/3.8, embed 302.6/310 KiB
  • Every new assertion was reintroduced-as-a-defect and watched fail, then restored — the two closed-list specs, the snapshot gate in both directions, the schema, the intersection, the correction, and the factory→fetcher wiring.

In a browser (pnpm review:embed + Playwright, against the built bundle)

checked result
locale=de-DE, nothing disabled German ✓
locale=fr-CA / nl-BE, nothing disabled French / Dutch ✓
locale=de-DE on an en/fr/nl atlas English, and no German bundle fetched ✓
Viewer picks French over a host-configured locale=de stays French ✓
Picker rows 3 when narrowed, 10 against production ✓
Path routing exercised for real — data-sahaj-atlas-ready reported {"routing":"path"} ✓
Compact card fetches clients/me + the language set and not the feed or region tree ✓

Review rounds

Four cleanup agents, one code review, one security review — all read-only. Worth surfacing rather than burying:

  • The code review caught a regression I introduced fixing the cleanup round's finding. Narrowing the host's locale= at the write site put an exact match in front of the one input i18next had always normalized, so every regional tag rendered English on an atlas where nothing was disabled. Fixed by resolving the way i18next does; checked against the library across 17 tags rather than against my own expectations — which also caught a false claim in one of my own new specs.
  • The two language effects raced. Both called changeLanguage on the mount commit and i18next has no ordering guard, so the last response won. Harmless until an operator switches English off, then a host's explicit locale=nl loses a coin-flip. Now one writer.
  • Security review: nothing exploitable. It confirmed the CMS-controlled code never reaches a sink — every element of the offered list originates in the hard-coded inventory, with the CMS string only ever the right-hand side of a Set.has(). Two items fixed: the sync script could send a local backend's key to production, and my own compact-card note named the wrong mechanism (the request comes from AppShell's observer, not the ungated warm — a compact gate would have removed nothing).

Notes for reviewer

  • SahajCloud deployed the languages field during this session. It answered {} when this branch started and returns all ten now, so the snapshot is a real sync rather than a documented guess. The schema still treats an absent field as parseable — that read answers 200 with {}, not 400, which stays reachable for an installation whose row predates the field.
  • pnpm types:cms was deliberately not run. It would now type the field, making sdk.findGlobal available in place of requestJson — but the sync pulls 600 lines of unrelated CMS drift, through which a renamed enum value rides invisibly (our zod schemas are hand-written). Worth doing as its own change; the fetcher's docblock says so.
  • Dismissed: moving the language guard above the client-record Suspense. It needs its own Suspense boundary (useLocale suspends until bundles load) and reintroduces a remount hazard in the most delicate part of the boot, to narrow a spinner whose label is deliberately untranslated English. Collapsing to one writer addressed what that finding was actually about.
  • Known and recorded, not fixed: the closed-list spec can be bypassed via i18nSharedOptions.supportedLngs, which is the inventory. Narrowing that export costs more than it buys (it is handed to i18next whole, by the app and by Ladle), so the spec says it is a deterrent rather than a proof.
  • Follow-up worth considering upstream: if languages rode on clients/me — which the widget already suspends on — the query factory, the warm and the narrowing window would all be unnecessary. A SahajCloud decision, not ours.

Closes #167

🤖 Generated with Claude Code

Ardnived and others added 7 commits August 25, 2026 15:22
`supportedLanguages` was a build-time constant pinned to `public/locales/`.
SahajCloud made the same list operator-configurable on the `sy-atlas-config`
global (sydevs/SahajCloud#645) and drives `hreflang` from it, so the two disagree
the first time somebody changes it.

The constant splits in two, because the question always had two halves and only
one of them belongs to this repo. `shippedLanguages` is the inventory — a fact
about `public/locales/` that only this build knows. `offeredLanguages` narrows
the operator's set to it, and that intersection is what the picker renders: a
code the CMS enables with no bundle here would be a menu row that silently does
nothing when clicked, and a bundle the CMS has switched off is a language
SahajCloud publishes no alternate for.

**Boot order: initialize with the shipped bundles, narrow once the config
arrives.** Deferring i18next's init would put a network read in front of first
paint on somebody else's page, and `supportedLngs` cannot be moved afterwards
without writing to `services.languageUtils` — i18next copies it in
`LanguageUtil`'s constructor. So it stays the shipped set, where its real job
("never fetch a bundle that does not exist") is a build fact anyway, and the
operator's set is applied where it can be applied honestly: the picker's rows,
and one guard in `AppShell` correcting whatever detection resolved.

There is no visible switch, because the read is warmed in parallel with the
`clients/me` read the tree already suspends on — so the operator's set is
already cached on the first render that can use it. That warm is deliberately
NOT gated on `compact`: the card is localized too, and one global read of a
ten-row array is not the feed-and-region-tree pair #161 took off that path.

Every failure lands on today's behaviour rather than an error screen. The field
does not exist in production yet — SahajCloud's change is on an unmerged branch,
and selecting a column the server lacks answers `{}` with a 200 — so the absent
case is the current one, and `AtlasConfigSchema` is written to parse it.

Closes #167

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…tainers

`docs/embedding.md` is the only documentation an embedding site reads, and the
picker's list is something they can watch change without touching their snippet.
So it gets a section of its own: what the setting is, why it is atlas-wide rather
than per-embed (the same list drives hreflang, so a per-page copy could
contradict a site's own search results), and the one operational catch — enabling
a language needs a bundle shipped here first.

No CSP change, and the guide says so: the read is another call to the API origin
hosts already allow.

The rule in `.claude/rules/i18n-and-state.md` described `supportedLanguages` as
BOTH the picker's list and `supportedLngs`. Those have separated, so it now
records which half went where, why `supportedLngs` must stay the shipped set, and
the boot-order measurement — warmed, the interface paints once in English; the
same response held back 3s paints German at 3.9s and flips at 5.4s. It also drops
a stale claim that `client.locale` still overrides detection, which stopped being
true in #165.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… is late

Path routing reads `clients/me` ABOVE `App` — `PathPrefix` needs the canonical
prefix before the router can be constructed — so App's mount effect, where the
language set is warmed, does not run until that read resolves. The warm then went
out one round trip later than in query mode, and the language guard could correct
a viewer's language after they had already seen a frame of it. Exactly the flash
the parallelism exists to prevent, in the one mode that had been reasoned about
rather than measured.

`PathBoot` renders the Suspense boundary rather than suspending itself, so it
commits and its effects run while the read is still in flight — the same shape
App relies on in query mode. Warming there restores the overlap.

Measured on the path-mode review page with `clients/me` held 700ms: it runs
211→978ms while the config read runs 225→275ms, so the operator's set is settled
703ms before the record it would otherwise have queued behind. The readiness
marker confirms the mode was genuinely path (`"routing":"path"`).

Calling it from both places is free — `prefetchQuery` returns immediately for an
entry already fresh or in flight — so App's effect is a no-op once this has run.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four cleanup agents over the branch diff. The substantive one is a defect they
found independently and I reproduced in a browser before fixing:

**A configured language was applied un-narrowed and corrected afterwards.**
`defaultLocale` (the `locale` parameter on the script URL) called
`changeLanguage` with whatever the host asked for, and the guard put it back —
which means i18next had already resolved it, FETCHED both of its namespaces and
broadcast the change. Measured on the review harness with `locale=de` against an
en/fr/nl atlas: `de/common` and `de/events` fetched and discarded, plus a visible
switch wherever the correction lands after first paint. Narrowing at the write
site makes it one call to the right language; measured again with the fix
reverted and restored, so the improvement is demonstrated rather than assumed.

⚠ Its sibling is NOT fixable there and the comment says so: `?locale=de` on the
page URL is read by i18next's own detector during `init`, before any of our code
exists. Those fetches happen regardless, and correcting afterwards is all that is
left — which is what the guard is now documented as being for.

The rest:

- `retryOnMount: false` on the query factory. React Query re-fetches whenever
  `data === undefined` and its in-flight dedupe excludes an already-rejected
  retryer, so a key without access to the global turned one optional read into
  four requests per page view. Verified in query-core 5.101.4 that the flag is
  read only on `status === 'error'`, so it cannot suppress the first fetch.
- The `.env.local` parser is `loadEnv` from vite, not a third hand-rolled copy —
  `serve-embed-review.mjs`'s docblock already records that a 15-line reader got
  precedence and quoting subtly wrong. It also picks `ATLAS_API_KEY` out of
  `.env.local`, which the copy silently did not.
- The sync script reports the missing-bundle case itself. It already held the
  live set; telling somebody to run two more commands to hear what this run knew
  is how a check stops being run.
- `offeredLanguages` loses a redundant early return — `new Set(undefined)` is
  empty, so absent-or-empty already fell through to the same tail.
- `getAtlasConfig` leaves the `api` default export, and its specs drive
  `atlasConfigQuery().queryFn()` instead. That is better coverage, not just less
  surface: it exercises the factory→fetcher wiring, which nothing else did.
- A closed-list spec pins who may read `shippedLanguages` and keeps the CI
  snapshot out of `src/` — the `href.test.ts` / `responsive.test.ts` pattern,
  because reaching for the inventory instead of the offer renders all ten
  languages and leaves every other gate green.
- The SettingsMenu story seeds the offered set through the shared factory, at
  module scope. It now demonstrates a narrowed picker (four rows of ten) and
  makes no network request at all; an effect-based seed still raced the query.

Dismissed: moving the guard out of `AppShell` into a `<LanguageGuard>` above the
client-record Suspense. It would need its own Suspense boundary (`useLocale`
suspends until the bundles load) and reintroduce a remount hazard in the most
delicate part of the boot, to narrow a spinner whose label is deliberately
untranslated English. Narrowing at the write site addresses what that finding was
actually about.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…argument

Two findings from the security review. Nothing exploitable was found; both of
these are about a credential going somewhere it was not issued for, and about
prose that would mislead the next person who reads it.

**The sync script could send a LOCAL backend's key to production.** It always
reads production, deliberately — a snapshot of seeded dev data asserted against
in CI is worse than none — but it accepted `VITE_SAHAJCLOUD_API_KEY` as a
fallback, and in the documented dev setup that variable pairs with a
`VITE_SAHAJCLOUD_URL` pointing at localhost. The 403 was the harmless half; the
`Authorization` header was already sent, and lands in production's request logs.
The fallback is now gated on that variable's own backend being production, and
the refusal says which origin the key belongs to — a correct refusal that reads
as an oversight is one somebody eventually "fixes".

**The compact-card note named the wrong mechanism.** Three docblocks, including
the inventory in `.claude/rules/components.md` that exists precisely for someone
auditing a collapsed card's requests, framed the read as a consequence of
`api.warmLanguages()` being ungated by `compact`. It is not: `AppShell` calls
`useLanguages()` unconditionally and renders for a collapsed card, so the
observer issues the request whether or not the warm is gated — a `compact` gate
would make the read serial and remove nothing. A future reviewer following that
reasoning would have "fixed" a request that never went away. The request is still
deliberate and the argument for it is unchanged; only the mechanism was wrong.

Also records why the render-phase ref write in `AppShell` is safe here — nothing
reads it during render, and its value derives from nothing but the query cache,
so a discarded render can only write the identical array.

Verified both directions of the key gate: pointed at production it syncs, pointed
at localhost it refuses and names the origin.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ne place

The code review found a regression I introduced fixing the PREVIOUS review's
finding — which is the trap `/finalize-pr` warns about, and it went unnoticed for
the reason the warning gives: my measurement used `locale=de`, already canonical.

**Every regional tag a host has ever shipped rendered English.** Narrowing
`defaultLocale` at the write site put an exact `includes` check in front of the
one input that has never been through i18next — the raw `locale=` from the script
URL. `de-DE`, `de-AT`, `fr-CA`, `nl-BE`, `es-MX`, `pt-br` all missed, on an atlas
where nothing had been disabled at all, contradicting both the changelog entry
and the embedding guide on the same branch. `preferredLanguage` now case-folds,
then tries the base language, then a regional variant of it — the same three
steps `supportedLngs` makes i18next take. `offeredLanguages` case-folds too, so a
lower-cased CMS row is not silently dropped.

Checked against i18next 24.2.3 rather than against my own expectations, and that
caught a false claim in one of my new specs: bare `pt` resolves to `en` on
i18next's explicit-`lng` path, not to the `pt-BR` we ship. We deliberately answer
`pt-BR` — its DETECTOR path does the same, and it is the better answer for a
Portuguese page — so the spec now says that instead of claiming the library
agrees. 16 of 17 tags agree exactly; the 17th is that deliberate divergence.

**And the two language effects are now one.** They both called `changeLanguage`
on the mount commit, and i18next has no ordering guard: `loadResources` returns
synchronously for a language already in the store and asynchronously for one that
must be fetched, so the last RESPONSE won. Invisible while the correction's
target was `en` (loaded at init by `fallbackLng`) — but an operator who switches
English off makes both targets need a fetch, and a host's explicit `locale=nl`
then loses a coin-flip. One writer, one target, no race. The `offered` ref and
its render-phase write go away with it.

Also from that review: `--write` exited 1 on the exact case it exists for, so
`--write && git commit` never reached the commit; it now refuses a row-shape
rename instead of silently storing `[]`; the closed-list spec matched prose as
well as code; the story seed lost the factory's `gcTime` and was evicted after
five minutes; and the host-facing docs claimed English where English may not be
offered.

Verified in a browser on the built bundle: `de-DE` → German, `fr-CA` → French,
`nl-BE` → Dutch, `de-DE` on an en/fr/nl atlas → English with no German bundle
fetched, and a viewer's own pick surviving a host-configured `locale=de`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The entry cited `[#167]` with no definition, so it rendered as literal text —
the same dangling-reference bug this branch already fixed for #165 one commit
earlier, which is a fair sign the check should not be by eye. Every `[#NNN]`
reference in the file now resolves.

Note the label is the ISSUE number and the target is the PR (168), matching how
the ticket is cited in the entry itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8d5579b
Status: ✅  Deploy successful!
Preview URL: https://b61812e2.sahajatlas.pages.dev
Branch Preview URL: https://feat-cms-language-set.sahajatlas.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8d5579b
Status: ✅  Deploy successful!
Preview URL: https://63783329.sahajatlas-design.pages.dev
Branch Preview URL: https://feat-cms-language-set.sahajatlas-design.pages.dev

View logs

@Ardnived

Ardnived commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing without merge: superseded by #198 (tracker sydevs/SahajCloud#702). The languages field this reads is being replaced by availableLocales (sydevs/SahajCloud#705), and the widget will read its translations from the CMS as well, so the shipped ∩ enabled split and the atlas-languages.json snapshot become moot. What carries over into #198: the measured boot order (warm the config read in parallel with clients/me; PathBoot reads clients/me above App), preferredLanguage, the single-writer changeLanguage finding, and the sync-script rule that a local key must never reach production.

@Ardnived Ardnived closed this Sep 5, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 12, 2026
`applyLanguage` is the one writer of the active language, but nothing ordered
two calls to it. `AppShell`'s layout effect keys on the offered set, which
answers the `['en']` floor until `sy-atlas-config` lands and the real set a
beat later — so a `?locale=fr` page issues `applyLanguage('fr', ['en'])` and
`applyLanguage('fr', [...])` within one frame, resolving to `en` and `fr`
respectively, both awaiting a bundle. Whichever read the network answered last
called `changeLanguage` last. A slow English read left the widget on English
permanently, under a French `<html lang>` — #168's failure reached through one
function instead of three.

A module-level generation counter, claimed before the first await and checked
before `applyBundle`, makes the ordering call order rather than settle order.
The catch branch is guarded too: a superseded request still reports its failure
but must not drag the widget back to English, because a newer call is already
deciding.

`src/config/language.test.ts` is new — the module had no spec. Both ordering
assertions were watched fail with the guards removed (`['fr', 'en']` instead of
`['fr']`) before being restored.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived pushed a commit that referenced this pull request Sep 12, 2026
…205)

* feat(i18n): source every string and the language set from SahajCloud

The widget's UI copy moves out of `public/locales/**` and into SahajCloud's
`sy-atlas-translations` global, read per locale beside `clients/me`. A committed
English snapshot (`src/config/translations.en.json`, written by
`pnpm sync:translations`) initialises i18next synchronously, types every `t()`
key, feeds Ladle and the specs, and is the last-resort fallback — while the CMS
still refreshes `en` at runtime, so an English edit ships without a deploy.

The languages the picker offers are now `sy-atlas-config.availableLocales`, a set
SahajCloud refuses to save until each locale's translations are published, so a
row in the menu is a row that leads somewhere. Anything unusable answers `['en']`.

`applyLanguage` (`config/language.ts`) is the single writer of the active
language, with exactly two callers: `AppShell`'s layout effect and
`useLocale().setLocale`. `applyRequestContext` now fills `?locale=` only when it
is absent, so the translations read — the one request whose locale is not the
active language — wins.

Every `t()` key is renamed through Appendix A of sydevs/SahajCloud#706, and the
two namespaces collapse to one. `i18next-http-backend`, `pnpm i18n:add`, the
`/locales/*` CORS rule and `VITE_HOST` all go with the bundles.

Closes #28, #167. Supersedes #168. Part of sydevs/SahajCloud#702.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(i18n): move the host contract and the i18n rules onto the CMS

`docs/embedding.md` is what an embedding site reads, so the CSP change lands there
in the same PR: `https://sahajatlas.com` leaves `connect-src` (nothing connects
there any more), `cloud.sydevelopers.com` now serves the strings as well as the
data, and the raw-key troubleshooting row becomes an English-copy one, since a
blocked read now shows English rather than dotted key names.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(changelog): link the entry to its pull request

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(ci): regenerate the lockfile without i18next-http-backend

Every job on this PR died at `pnpm install --frozen-lockfile` with
`ERR_PNPM_OUTDATED_LOCKFILE`, including both Cloudflare Pages builds, so
nothing in CI ran against the change at all. The branch removed
`i18next-http-backend` from `package.json` when the locale bundles moved to
the CMS, but left the lockfile's entry for it in place.

`pnpm install` drops that importer entry, the package, and its transitive
`cross-fetch`. Nothing else moves. `pnpm install --frozen-lockfile` now
resolves, and the full gate is green on the result: lint, typecheck, 1455
tests in 114 files, `pnpm build`, and `pnpm size` (standalone 295.4 KiB,
embed 297.9 KiB, loader 2.6 KiB, all under budget).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(i18n): order two overlapping applyLanguage calls

`applyLanguage` is the one writer of the active language, but nothing ordered
two calls to it. `AppShell`'s layout effect keys on the offered set, which
answers the `['en']` floor until `sy-atlas-config` lands and the real set a
beat later — so a `?locale=fr` page issues `applyLanguage('fr', ['en'])` and
`applyLanguage('fr', [...])` within one frame, resolving to `en` and `fr`
respectively, both awaiting a bundle. Whichever read the network answered last
called `changeLanguage` last. A slow English read left the widget on English
permanently, under a French `<html lang>` — #168's failure reached through one
function instead of three.

A module-level generation counter, claimed before the first await and checked
before `applyBundle`, makes the ordering call order rather than settle order.
The catch branch is guarded too: a superseded request still reports its failure
but must not drag the widget back to English, because a newer call is already
deciding.

`src/config/language.test.ts` is new — the module had no spec. Both ordering
assertions were watched fail with the guards removed (`['fr', 'en']` instead of
`['fr']`) before being restored.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(i18n): warm the locale the boot effect applies

`warmTranslations(i18n.language)` warmed a query key `applyLanguage` may never
read. `i18n.language` is the raw detected tag (`querystring → hostHtmlLang →
navigator`); `AppShell` applies `pageLocaleOverride(search) ?? defaultLocale ??
i18n.language` through `preferredLanguage`. They diverge in two ordinary cases:

- a host passing `locale="fr"`, which reaches the widget as `defaultLocale` and
  sits in no detector, so the browser's tag was warmed while French was
  fetched — the documented `locale` parameter got the visible flip the warm-up
  exists to prevent;
- a browser reporting `en-US`, which `preferredLanguage` narrows to `en`, so
  most loads paid for a request nothing read.

`bootLanguage` applies the same precedence, and narrows the one way that needs
no `availableLocales` — the set has not arrived yet, being the other half of
this same warm-up. `?locale=` is warmed verbatim, since the widget writes that
parameter itself out of the offered set and an exact match wins step 1. The
attribute and the browser tag are base-tagged, which is step 2. Both `App` and
`PathBoot` call it, so the two warm-ups still merge on one key.

Five new assertions in `src/config/language.test.ts`, each watched fail against
the old `i18n.language` before the fix went in. The last one states the
property directly: the key warmed equals what `preferredLanguage` resolves.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(i18n): pin the widget tab list to one source

`WIDGET_TRANSLATION_TABS` was exported and referenced nowhere, while the same
list was stated four times: that constant, `TRANSLATION_SELECT` in
`config/api/fetch.ts`, the `Pick<>` in `WidgetTranslations`, and the check in
`scripts/sync-translations.mjs`. Adding a tab meant editing three of the four,
and nothing failed if you missed one — the sync script fetches everything and
strips, so a group the CMS added reached the snapshot without ever being
requested at runtime.

`WidgetTranslations` now `Pick`s by the constant, which removes one copy and
makes the constant load-bearing. The other two cannot import it: the SDK
type-checks `TRANSLATION_SELECT` against the generated CMS types, which needs
its `true` literals, and the sync script is a node `.mjs` with no compiler. So
a spec holds all three together instead. The script's list moves into a named
`WIDGET_TABS` const so the spec has a stable anchor.

Watched fail: adding `'emails'` to the constant alone turns the new spec red.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(i18n): derive the filter and sort key families

The docblock promised "each family below is derived from the constant that
generates it, never from a hand-written list", and two of the four were not.
`FILTER_OPTIONS` and `SORT_ORDERS` spelled their options out here, so adding a
filter format or a sort order did need an edit in this file — the opposite of
what the reader is told, and exactly the stale copy the second direction of
this gate exists to catch elsewhere.

`TIME_PERIODS` and `SORT_ORDERS` are already exported from `lib/shape`, so
those import. `FORMAT_OPTIONS` and `CADENCE_OPTIONS` are module-local to the
component that renders them, so a new `arrayLiterals` reads them out of its
source the way `WEEK_NUMBERS` reads `use-event-display.ts`. Only each group's
fixed chrome — its `label`, and the `any` that clears it — stays written down,
because neither is an option in any of those tables.

Reading a table out of source has its own failure: a renamed constant returns
`[]` and every assertion downstream passes for a reason unrelated to the copy,
with `DYNAMIC_KEYS` still clearing its floor on the families that do match. So
a spec asserts each regex-read family found something. It asserts emptiness
only — pinning the contents would put the hand-written list back one file over.

Watched fail twice: renaming `FORMAT_OPTIONS` reds the new guard by name, and
adding a real third format reds the resolve check with no test edit, which is
what proves the derivation is live.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(fonts): the subset set is the CMS's answer now

`fonts.ts` still said the shipped subsets were "limited to what `public/locales`
needs", a directory #198 deleted. #198 listed the file and the rename was
missed.

The correction is not only a path. That listing WAS the offered language set,
so a new language and its subset necessarily arrived in one commit. The set now
comes from `sy-atlas-config.availableLocales` at runtime, which means an
operator publishing a locale in a script neither face covers gets the system
sans, with every gate here green. The docblock says so.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(i18n): record the ordering and warm-up rules

Both findings this PR just fixed were reachable because the subsystem rule said
"one writer" and stopped there. It now says what the counter in `language.ts`
is for, and that the boot warm-up goes through `bootLanguage` rather than
`i18n.language`, so the next reader does not re-derive either.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* style(i18n): drop the trailing comma prettier rejects

`<T,>` is the .tsx disambiguator, and this file is .ts, where it is just a
trailing comma. `--max-warnings 0` makes it a CI failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(i18n): one word per concept — locale, language, translations

The reviewer asked for consistent terminology across the files #198 adds.
Three words named two things, mixed inside single expressions: `applyLanguage`
took `available` locales, resolved a `preferred`, and handed it to
`applyBundle(locale, …)`; `useLanguages()` returned `availableLocales`; a
`languages` variable fed `pageLocaleOverride`. Every input and output on this
path is spelled `locale` by the CMS, the host attribute and the query
parameter, so the code was the only place using a second word for it.

The split is now stated once, in `docs/rules/i18n-and-state.md`:

- LOCALE — a BCP-47 tag the widget can render in. Everything that resolves,
  narrows, stores or fetches one is named for it: `applyLocale`, `bootLocale`,
  `preferredLocale`, `useAvailableLocales`, `currentLocales`, `localesFrom`,
  `FALLBACK_LOCALES`, and the files `config/locale.ts` and
  `hooks/use-available-locales.ts`.
- LANGUAGE — a human language as content: an event's spoken language in a
  filter, a display name for one, and `useLocale().languageCode`, the base
  subtag a font subset keys on. `languageLabel` and `nativeLanguageLabel` keep
  their names because they are about that axis, not this one.
- TRANSLATIONS — the strings: one bundle per locale.

Rename only. No call site changes behaviour, and the docs naming these symbols
move with them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(i18n): stop exporting two helpers nobody imports

`FALLBACK_LOCALES` and `localesFrom` were exported and referenced only inside
this file — grepped across `src`, `scripts`, `tests` and `.ladle`. An export is
a claim that a second caller exists, and a reader who goes looking for one
spends the trip finding out there is none.

There are exactly two ways to ask for the offered set, and both stay exported:
`useAvailableLocales` for a render, `currentLocales` for an event handler.
`localesFrom` is what keeps those two from answering differently, which is a
reason to keep the function, not to publish it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(i18n): resolve ?locale= case-insensitively, as preferredLocale does

`pageLocaleOverride` and `preferredLocale` answer the same question — does this
tag resolve against the offered set — and they cannot share code: `lib/shape`
imports nothing from `config/`, because `config/i18n-options.ts` already imports
`LOCALE_PARAM` from there and the cycle would surface as a boot-time TDZ error
that typecheck cannot see.

Two hand-kept copies of one rule had drifted on exactly one input. `?locale=PT-br`
resolves to `pt-BR` in `preferredLocale`, whose spec asserts it, and missed here.
A miss is not "fall back to English": it hands the decision to `defaultLocale`,
so a host's `locale="fr"` would have beaten a page URL asking for Portuguese —
the precise inversion this function exists to prevent.

The widget's own links are unaffected: `publishLocale` writes the offered code
verbatim. This is about a link a host or a person wrote.

Spec watched fail on all three casings before the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(i18n): record that ?locale= matching ignores case

The host contract changes with the fix one commit back: a page URL whose locale
tag is cased differently from the offered code is now honoured where it used to
fall through to the snippet's own `locale` parameter. `docs/embedding.md` and
`CHANGELOG.md` are the only documentation an embedding site reads, so both carry
it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

feat(i18n): take the language set from SahajCloud, not from supportedLanguages

1 participant