diff --git a/package.json b/package.json index d879c0a..ccf9f3b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "test": "vitest", "test:watch": "vitest --watch", "redis:up": "docker compose up -d redis", - "redis:down": "docker compose stop redis" + "redis:down": "docker compose stop redis", + "validate-locales": "node scripts/validate-locales.js" }, "dependencies": { "@octokit/graphql": "^9.0.3", diff --git a/scripts/validate-locales.js b/scripts/validate-locales.js new file mode 100644 index 0000000..e34f91a --- /dev/null +++ b/scripts/validate-locales.js @@ -0,0 +1,22 @@ +/* eslint-disable @typescript-eslint/no-require-imports */ +const fs = require('fs'); +const path = require('path'); + +const localesDir = path.join(__dirname, '..', 'locales'); +const enKeys = Object.keys(JSON.parse(fs.readFileSync(path.join(localesDir, 'en.json'), 'utf8'))).sort(); + +let hasError = false; + +fs.readdirSync(localesDir).forEach(file => { + if (file === 'en.json') return; + + const fileKeys = Object.keys(JSON.parse(fs.readFileSync(path.join(localesDir, file), 'utf8'))).sort(); + const missing = enKeys.filter(k => !fileKeys.includes(k)); + const extra = fileKeys.filter(k => !enKeys.includes(k)); + if (missing.length || extra.length) { + hasError = true; + console.error(`${file}: ${missing.length ? `Missing keys: ${missing.join(', ')}` : ''}${extra.length ? ` Extra keys: ${extra.join(', ')}` : ''}`); + } +}); + +process.exit(hasError ? 1 : 0);