/** * One-off generator, run by hand whenever the catalog's reference data * changes (a new ingredient/diet/allergen added to * `db/reference-seed-data.ts`, or an English key corrected in * `catalog-en-keys.ts`): regenerates * `apps/web/src/locales/fr/translation.json`'s * `catalog.{diets,allergens,ingredients}` sections (English key -> French * label), merged in without touching the rest of the file. * * Doesn't touch the database — a brand new diet/allergen/ingredient is * created fresh by `seedReferenceData`'s normal create path (see * `reference-seed-data.ts`), no backfill needed. Renaming an *existing* * item's English key in `catalog-en-keys.ts` does need a one-off migration * (`UPDATE ... SET key = ...`, keyed by the *old* key value) written by * hand for that occasion — see * `prisma/migrations/20260818193000_catalog_keys_to_english/` for the shape * one looks like. * * Never imported by the app itself — a dev-time tool, run via * `tsx scripts/generate-catalog-i18n.ts`. */ import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { getEnglishKey } from "../src/db/catalog-en-keys.js"; import { ALLERGENS, DIETS, INGREDIENT_GROUPS } from "../src/db/reference-seed-data.js"; const here = fileURLToPath(new URL(".", import.meta.url)); function toKeyLabelMap(labels: string[]): Record { const map: Record = {}; for (const label of labels) { map[getEnglishKey(label)] = label; } return map; } const diets = toKeyLabelMap(DIETS); const allergens = toKeyLabelMap(ALLERGENS.map((a) => a.name)); const ingredients = toKeyLabelMap(INGREDIENT_GROUPS.flatMap((g) => g.items.map((i) => i.name))); console.log( `diets: ${Object.keys(diets).length}, allergens: ${Object.keys(allergens).length}, ingredients: ${Object.keys(ingredients).length}`, ); const localePath = here + "../../web/src/locales/fr/translation.json"; const locale = JSON.parse(readFileSync(localePath, "utf8")); locale.catalog = { diets, allergens, ingredients }; writeFileSync(localePath, JSON.stringify(locale, null, 2) + "\n"); console.log(`wrote ${localePath}`);