Skip to content

fix(i18n): production hygiene for logging, locales, and storage #95

Closed

Description

@Ardnived

Summary

Four production-hygiene defects in the i18n/telemetry layer, all host-visible and all from the release-readiness review (.claude/reports/RELEASE_READINESS.md §1.6, §3.5, Appendices A/B): i18next debug logging ships to every host page's console (verified live in the deployed production bundle), eight of the ten shipped locales are unreachable from the language picker, the language detector's library defaults silently read cookies and write localStorage on the host's origin (undeclared, and the one storage path not defensively wrapped), and two third-party data flows — Fathom analytics and ipwho.is IP geolocation — run consent-ungated and undocumented to integrators. The last three are a GDPR exposure surface for any EU host.

Proposed changes

1. Gate i18next debug to dev

src/config/i18n.ts:21 passes debug: true unconditionally. Change to debug: import.meta.env.DEV so production hosts get a silent console and dev keeps the missing-key warnings.

2. Expose all shipped locales in the language picker

supportedLanguages = ['en', 'fr'] (src/config/i18n.ts:8) while ten locale bundles ship in public/locales/: cs, de, en, es, fr, hu, nl, pt-BR, ru, uk. SettingsMenu builds the picker from this const (src/components/molecules/SettingsMenu/SettingsMenu.tsx:15,87), so eight locales are unreachable despite being fully bundled.

  • Extend supportedLanguages to the shipped set.
  • Cross-check the locale-set-alignment policy first: SahajAtlas languages must be a subset of SahajCloud's (SahajCloud src/lib/locales/index.ts is the source of truth). The client sends the resolved i18next language to SahajCloud 1:1 (applyRequestContext), so a locale the CMS doesn't support gets untranslated content or errors. hu + nl were missing on the SahajCloud side → translations: add Hungarian (hu) and Dutch (nl) locales SahajCloud#578. Record in the implementation report any locale that can't be exposed yet and why.
  • Check MAP_WORLDVIEWS per .claude/rules/mapbox.md for any newly exposed locale needing a worldview entry.

3. Make language detection explicit; stop the undeclared host-origin storage write

src/config/i18n.ts:23-25 configures i18next-browser-languagedetector with only { lookupQuerystring: 'locale' }, so the library's defaults silently apply: the detection order reads cookies and localStorage, and caches: ['localStorage'] writes i18nextLng onto the HOST page's origin. Two defects:

  • Undeclared storage on someone else's origin — disclosure-relevant (report §3.5).
  • It is the one storage path not try/catch-wrapped: a sandboxed-iframe embed (sandbox without allow-same-origin) throws on localStorage access. Compare the deliberate defensive wrapping in src/hooks/use-theme.ts:124-146.

Fix: set an explicit order (querystring + navigator) and caches: []. If persistence is deliberately kept instead, it must be both declared in the README privacy section and wrapped so a sandboxed embed can't throw.

4. Disclose + gate the third-party data flows

  • Fathom (src/App.tsx:147-159; the full analytics block is ~137-159): Fathom.load(import.meta.env.VITE_FATHOM_ID) injects the tracker script into the host page whenever the env var is set and the client record carries a non-localhost primary domain — no consent gate, no host opt-out, unmentioned in any host-facing doc. Add a host-facing opt-out (e.g. an analytics="false" attribute on <sahaj-atlas>, or document the build-time gate explicitly) and disclose the tracker + its conditions in the README.
  • ipwho.is (src/hooks/use-ip-location.ts:9-32): the visitor's IP goes to a free third-party geolocation service once per session, passively. The existing mitigations are good — referrerPolicy: 'no-referrer', 5s AbortSignal.timeout, never throws, deliberately a bare fetch so the SahajCloud API key can't leak — but the call is consent-ungated and undocumented, and an IP is personal data under GDPR (report §3.5). Implementer proposes the resolution in-ticket: either gate the lookup behind an explicit interaction (e.g. fire only once the nearby-search suggestion flow is actually engaged/shown) or keep it passive but document it prominently in the README privacy section. Defend the choice with the GDPR framing in the implementation report.

Acceptance criteria

  • The production bundle emits no i18next debug logging; dev behaviour unchanged
  • The settings language picker lists every shipped locale that SahajCloud supports; any locale still excluded is named in the implementation report with the reason (subset policy / translations: add Hungarian (hu) and Dutch (nl) locales SahajCloud#578)
  • Language detection order and caches are explicit in src/config/i18n.ts; no undeclared host-origin storage write remains — or the write is declared in the README and wrapped so a sandboxed iframe cannot throw
  • A host can opt out of Fathom (attribute or documented build-time gate), and Fathom's presence + load conditions are disclosed in the README
  • The ipwho.is decision (gate vs. document) is implemented, with the GDPR reasoning recorded in the implementation report
  • README gains an additive privacy/storage disclosure section for integrators covering: Fathom (conditions + opt-out), ipwho.is, every storage key the widget touches (theme, geolocation dismissal, language cache if kept), and the corresponding connect-src/script-src CSP targets — updated additively alongside the existing CSP section, no rewrites of unrelated content
  • Unit-lane tests where expressible (e.g. supportedLanguages ⊆ shipped public/locales/ parity; detector options shape) per .claude/rules/tests.md
  • pnpm lint && pnpm typecheck && pnpm test:run pass
  • Write an implementation report to .claude/reports/<issue-number>-<short-slug>.md — in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved

Files affected

  • src/config/i18n.ts — debug gate, supportedLanguages, explicit detection options
  • src/config/i18n-options.ts — only if shared options move here
  • src/hooks/use-ip-location.ts — gating decision
  • src/App.tsx — the Fathom/analytics block ONLY (lines ~137-159); keep the edit surgical
  • src/components/molecules/SettingsMenu/ — locale-list consumer
  • README.md — additive privacy-disclosure section (+ CSP table rows for any flow kept)

Parallel implementation: this ticket OWNS the files listed above; sibling release-hardening tickets run concurrently — avoid edits outside owned files except strictly additive ones (e.g. appended README sections, new locale keys). In particular, a sibling ticket owns the rest of src/App.tsx — touch only the analytics block.

References

Activity

  1. added a commit that references this issue on Aug 7, 2026
    df7b260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions