/** * Ajoute récursivement les clés présentes dans locales/en.json mais absentes * des autres fichiers (valeur = texte anglais, à retraduire si besoin). * Usage: node scripts/merge-missing-locale-keys.mjs */ import fs from 'fs' import path from 'path' import { fileURLToPath } from 'url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const localesDir = path.join(__dirname, '..', 'locales') const enPath = path.join(localesDir, 'en.json') function mergeMissing(target, source) { for (const [k, v] of Object.entries(source)) { if (v !== null && typeof v === 'object' && !Array.isArray(v)) { if (!target[k] || typeof target[k] !== 'object' || Array.isArray(target[k])) { target[k] = {} } mergeMissing(target[k], v) } else { if (!(k in target)) target[k] = v } } } const en = JSON.parse(fs.readFileSync(enPath, 'utf8')) for (const name of fs.readdirSync(localesDir)) { if (!name.endsWith('.json') || name === 'en.json') continue const p = path.join(localesDir, name) const loc = JSON.parse(fs.readFileSync(p, 'utf8')) mergeMissing(loc, en) fs.writeFileSync(p, JSON.stringify(loc, null, 2) + '\n') } console.log('merge-missing-locale-keys: OK')