#!/usr/bin/env node /** * Genere extension/_locales//messages.json depuis i18n/translations.json * Usage: node scripts/build-extension-locales.mjs */ import fs from 'fs' import path from 'path' import { fileURLToPath } from 'url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const extRoot = path.resolve(__dirname, '..') const srcPath = path.join(extRoot, 'i18n', 'translations.json') const outRoot = path.join(extRoot, '_locales') const { version, strings } = JSON.parse(fs.readFileSync(srcPath, 'utf8')) const langs = Object.keys(strings) for (const lang of langs) { const dir = path.join(outRoot, lang) fs.mkdirSync(dir, { recursive: true }) const messages = {} for (const [key, def] of Object.entries(strings[lang])) { const entry = { message: def.message.replace(/\{version\}/g, version) } if (def.description) entry.description = def.description if (def.placeholders) entry.placeholders = def.placeholders messages[key] = entry } fs.writeFileSync(path.join(dir, 'messages.json'), JSON.stringify(messages, null, 2) + '\n') } console.log(`Generated ${langs.length} locales in ${outRoot}`)