Files
HealthLog/scripts/generate-i18n-boot.mjs
T
aucun6352 f1b0420479 feat(i18n): add Korean as a seventh end-to-end locale
Register `ko` in the locale list, language names, and labels, and ship
messages/ko.json so the whole UI — dashboard, settings, share views,
clinician PDF, notifications, and AI prompts — renders in Korean.

Extend the locale-parity, English-leak, plural-completeness, and copy
guard tests to cover the new locale, and update README/CONTRIBUTING to
list Korean among the supported languages.
2026-08-26 16:42:45 +09:00

53 lines
2.0 KiB
JavaScript

#!/usr/bin/env node
/**
* Generate the locale-catalog boot scripts (`public/i18n/<locale>.js`).
*
* The root layout emits `<script src="/i18n/<locale>.js?v=<version>" defer>`
* ahead of Next's hydration scripts; the body assigns the active locale's
* full message bundle to `self.__HL_I18N`, which `src/lib/i18n/load-locale.ts`
* reads in its browser cache initializer. This replaces the former RSC-prop
* handoff that serialized the ENTIRE active catalog into every document's
* flight payload (392 KB of a 505 KB dashboard HTML, re-downloaded on every
* hard load).
*
* Static `public/` files (rather than a route handler) because Next serves
* them with an ETag — repeat loads revalidate to a 304 instead of
* re-downloading the catalog — and the service worker caches the versioned
* URL cache-first for the offline relaunch. The `?v=` query the layout
* appends busts both caches per deploy.
*
* Runs as a `prebuild`/`predev` step (the `sw-version.js` pattern); output
* is gitignored. Content is the same public catalog JSON that ships in the
* repository — no tenant data, no secrets.
*/
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = join(__dirname, "..");
const outDir = join(repoRoot, "public", "i18n");
const LOCALES = ["de", "en", "fr", "es", "it", "pl", "ko"];
mkdirSync(outDir, { recursive: true });
const banner =
"// AUTO-GENERATED by scripts/generate-i18n-boot.mjs — do not edit.\n";
for (const locale of LOCALES) {
const messages = JSON.parse(
readFileSync(join(repoRoot, "messages", `${locale}.json`), "utf8"),
);
const payload = JSON.stringify({ locale, messages });
writeFileSync(
join(outDir, `${locale}.js`),
`${banner}self.__HL_I18N = ${payload};\n`,
"utf8",
);
}
process.stdout.write(
`generate-i18n-boot: wrote ${LOCALES.length} catalogs to public/i18n/\n`,
);