mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
Add pt-BR to the locale list and everything that hangs off it: the client loader, Intl and date-fns mapping, the reply-language footers of the Coach and insights prompts (English body, pt-BR footer, the same path Korean and Dutch take), the citation-coverage normative words, the no-key fallback copy, the AUDIT-C standard-drink line, country labels, period search, CSV yes/no cells and the Telegram bare-word aliases. The locale enums in the extract, managed-profile and record-settings schemas now derive from the locale list instead of repeating it, and the five notification and login-alert routes share one isLocale guard instead of hand-rolled chains, so a later locale is one edit there. A language tag is matched exactly and case-insensitively before its primary subtag, so pt-BR and pt-PT browsers land on the Portuguese bundle rather than English, and AUDIT-C no longer cuts a region tag to two letters. PHQ-9, GAD-7 and WHO-5 are not marked validated for pt-BR: the wording has not been read against the published Brazilian forms, so readers get the English items plus the existing note.
53 lines
2.0 KiB
JavaScript
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", "nl", "pt-BR"];
|
|
|
|
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`,
|
|
);
|