/** * Recursively copies missing keys from en.json into es.json (does not overwrite * existing Spanish strings). Fixes ngx-translate showing raw keys like WORKSPACE.SHELL.*. * * After running this, optionally run `node tools/i18n/apply-shell-es-ui.mjs` to * replace merged English workspace shell strings with Spanish for KiraTV / es UI. */ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const root = path.resolve(__dirname, '..', '..'); const enPath = path.join(root, 'apps/web/src/assets/i18n/en.json'); const esPath = path.join(root, 'apps/web/src/assets/i18n/es.json'); function fillMissing(enVal, esVal) { if (enVal === null || typeof enVal !== 'object' || Array.isArray(enVal)) { return esVal !== undefined ? esVal : enVal; } const out = esVal !== null && typeof esVal === 'object' && !Array.isArray(esVal) ? { ...esVal } : {}; for (const [k, v] of Object.entries(enVal)) { if (out[k] === undefined) { out[k] = Array.isArray(v) ? [...v] : v; } else if ( v !== null && typeof v === 'object' && !Array.isArray(v) && typeof out[k] === 'object' && !Array.isArray(out[k]) ) { out[k] = fillMissing(v, out[k]); } } return out; } const en = JSON.parse(fs.readFileSync(enPath, 'utf8')); const es = JSON.parse(fs.readFileSync(esPath, 'utf8')); const merged = fillMissing(en, es); fs.writeFileSync(esPath, JSON.stringify(merged, null, 4) + '\n'); console.log('Merged missing i18n keys from en.json into es.json');