const fs = require('fs'); const path = require('path'); const localesDir = path.join(__dirname, '..', 'src', 'i18n', 'locales'); // Load main locale files const zhCN = JSON.parse(fs.readFileSync(path.join(localesDir, 'zhCN.json'), 'utf8')); const enUS = JSON.parse(fs.readFileSync(path.join(localesDir, 'enUS.json'), 'utf8')); const viVN = JSON.parse(fs.readFileSync(path.join(localesDir, 'viVN.json'), 'utf8')); // Deep merge function function deepMerge(target, source) { for (const key in source) { if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key])) { if (!target[key]) target[key] = {}; deepMerge(target[key], source[key]); } else { if (!target[key]) target[key] = source[key]; } } return target; } // Process pending files const pendingFiles = fs.readdirSync(localesDir).filter(f => f.startsWith('_pending') && f.endsWith('.json')); for (const file of pendingFiles) { const filePath = path.join(localesDir, file); const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); // Each pending file has zh/en/vi sections if (data.zh) deepMerge(zhCN, data.zh); if (data.en) deepMerge(enUS, data.en); if (data.vi) deepMerge(viVN, data.vi); console.log('Merged:', file); } // Write back fs.writeFileSync(path.join(localesDir, 'zhCN.json'), JSON.stringify(zhCN, null, 2), 'utf8'); fs.writeFileSync(path.join(localesDir, 'enUS.json'), JSON.stringify(enUS, null, 2), 'utf8'); fs.writeFileSync(path.join(localesDir, 'viVN.json'), JSON.stringify(viVN, null, 2), 'utf8'); // Count keys function countKeys(obj) { let c=0; for(const k in obj){if(typeof obj[k]==='object'&&obj[k]!==null) c+=countKeys(obj[k]); else c++;} return c; } console.log('zhCN:', countKeys(zhCN)); console.log('enUS:', countKeys(enUS)); console.log('viVN:', countKeys(viVN)); // Remove pending files for (const file of pendingFiles) { fs.unlinkSync(path.join(localesDir, file)); console.log('Removed:', file); }