Skip to content

feat(browser): YAML-first translations#48

Merged
ronaldtse merged 1 commit into
mainfrom
feat/yaml-first-translations
Jul 22, 2026
Merged

feat(browser): YAML-first translations#48
ronaldtse merged 1 commit into
mainfrom
feat/yaml-first-translations

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Translators work in YAML, not JS literals. The runtime i18n table now ships as six per-locale YAML files parsed at build time. Consumer overrides gain a symmetric loader.

Added

  • loadYamlTranslations(yamlString) helper, exported from @edoxen/browser. Parses a YAML mapping of 'key': 'value' pairs into a frozen UiStrings record. Throws on non-mapping input, ignores non-string values, returns {} for empty input.
  • src/i18n/strings/{eng,fra,zho,spa,ara,rus}.yaml — built-in locale tables extracted from the TS literal that used to live inline in ui.ts. Same keys, same values, just YAML. Translators can read these as worked examples.
  • src/i18n/load-translations.spec.ts — six tests covering parsing, unicode/quote escaping, empty input, malformed input, freeze guarantee.

Changed

  • src/i18n/ui.tsSTRINGS const now references BUILTIN_STRINGS (loaded from YAML via ?raw imports); the 557-line inline table is gone. loadYamlTranslations is re-exported for consumers.
  • src/virtual.d.ts — declares *.yaml?raw and *.yml?raw modules so TypeScript accepts Vite's raw YAML imports.
  • README §Custom translations rewritten to make YAML the primary path. Option A (file-based, recommended) loads via readFileSync + loadYamlTranslations; Option B (inline literals) still works for small overrides. Includes YAML escaping rules (' doubling inside single-quoted scalars, or backslash escapes in double-quoted).

Migration notes

No breaking changes — inline uiStrings: { fra: {...} } literals still work. Consumers who want file-based translations can adopt the new helper without touching existing config. Built-in English + French values are byte-for-byte unchanged.

Test plan

  • pnpm -F @edoxen/browser typecheck — clean.
  • pnpm -F @edoxen/browser test — 183 passed (was 177; +6 new loader spec tests).
  • pnpm -F @edoxen/browser test:e2e — 51 passed.
  • pnpm -F @edoxen/browser build — built-site HTML contains the expected translated strings (Plenary / Resolutions / Meetings).

Post-merge

Trigger release.yml via workflow_dispatch to publish @edoxen/browser@0.10.0 (minor — new public helper).

Translators work in YAML, not JS literals. Built-in i18n table moves from a 557-line TS literal in ui.ts to six per-locale YAML files (src/i18n/strings/<locale>.yaml) parsed at build time via Vite ?raw + the yaml package. Consumer overrides gain a symmetric loadYamlTranslations() helper.

API surface unchanged: inline uiStrings literals still work. Consumers who want file-based translations can adopt the new helper without touching existing config.

README rewritten to make YAML the primary path. load-translations.spec.ts covers parsing, unicode, escaping, and the freeze guarantee. 183 unit + 51 e2e green.
@ronaldtse
ronaldtse merged commit 5501082 into main Jul 22, 2026
2 checks passed
@ronaldtse
ronaldtse deleted the feat/yaml-first-translations branch July 22, 2026 14:07
ronaldtse added a commit that referenced this pull request Jul 22, 2026
Consumes the changeset from PR #48. Bumps @edoxen/browser 0.9.0 -> 0.10.0 (minor: new public loadYamlTranslations helper + YAML-based built-in locale tables).
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