diff --git a/services/web/scripts/translations/checkCoverage.js b/services/web/scripts/translations/checkCoverage.js new file mode 100644 index 0000000000..f3562fbde7 --- /dev/null +++ b/services/web/scripts/translations/checkCoverage.js @@ -0,0 +1,35 @@ +const fs = require('fs') +const Path = require('path') + +const LOCALES = Path.join(__dirname, '../../locales') +const SORT_BY_PROGRESS = process.argv.includes('--sort-by-progress') + +function count(file) { + return Object.keys(require(Path.join(LOCALES, file))).length +} + +async function main() { + const EN = count('en.json') + const rows = [] + + for (const file of await fs.promises.readdir(LOCALES)) { + if (file === 'README.md') continue + const n = count(file) + const name = file.replace('.json', '') + rows.push({ + name, + done: n, + missing: EN - n, + progress: ((100 * n) / EN).toFixed(2).padStart(5, ' ') + '%', + }) + } + if (SORT_BY_PROGRESS) { + rows.sort((a, b) => b.done - a.done) + } + console.table(rows) +} + +main().catch(error => { + console.error(error) + process.exit(1) +}) diff --git a/services/web/scripts/translations/cleanupUnusedLocales.js b/services/web/scripts/translations/cleanupUnusedLocales.js index bf3f15a5d1..2490b081cb 100644 --- a/services/web/scripts/translations/cleanupUnusedLocales.js +++ b/services/web/scripts/translations/cleanupUnusedLocales.js @@ -4,6 +4,7 @@ const { execSync } = require('child_process') const EN_JSON = Path.join(__dirname, '../../locales/en.json') const CHECK = process.argv.includes('--check') +const SYNC_NON_EN = process.argv.includes('--sync-non-en') async function main() { const locales = JSON.parse(await fs.promises.readFile(EN_JSON, 'utf-8')) @@ -82,6 +83,28 @@ async function main() { unusedKeys.push(key) } } + + if (SYNC_NON_EN) { + if (CHECK) { + throw new Error('--check is incompatible with --sync-non-en') + } + const LOCALES = Path.join(__dirname, '../../locales') + for (const name of await fs.promises.readdir(LOCALES)) { + if (name === 'README.md') continue + if (name === 'en.json') continue + const path = Path.join(LOCALES, name) + const locales = JSON.parse(await fs.promises.readFile(path, 'utf-8')) + for (const key of Object.keys(locales)) { + if (!found.has(key)) { + delete locales[key] + } + } + const sorted = + JSON.stringify(locales, Object.keys(locales).sort(), 2) + '\n' + await fs.promises.writeFile(path, sorted) + } + } + if (unusedKeys.length === 0) { return }