Skip to content

Commit 287869c

Browse files
authored
feat: add locale keys validation script (#166) (#168)
* feat: add locale keys validation script (#166) * fix(validate-locales.js): Add ESLint disable comment for require imports
1 parent d9d796a commit 287869c

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"test": "vitest",
1111
"test:watch": "vitest --watch",
1212
"redis:up": "docker compose up -d redis",
13-
"redis:down": "docker compose stop redis"
13+
"redis:down": "docker compose stop redis",
14+
"validate-locales": "node scripts/validate-locales.js"
1415
},
1516
"dependencies": {
1617
"@octokit/graphql": "^9.0.3",

scripts/validate-locales.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const localesDir = path.join(__dirname, '..', 'locales');
6+
const enKeys = Object.keys(JSON.parse(fs.readFileSync(path.join(localesDir, 'en.json'), 'utf8'))).sort();
7+
8+
let hasError = false;
9+
10+
fs.readdirSync(localesDir).forEach(file => {
11+
if (file === 'en.json') return;
12+
13+
const fileKeys = Object.keys(JSON.parse(fs.readFileSync(path.join(localesDir, file), 'utf8'))).sort();
14+
const missing = enKeys.filter(k => !fileKeys.includes(k));
15+
const extra = fileKeys.filter(k => !enKeys.includes(k));
16+
if (missing.length || extra.length) {
17+
hasError = true;
18+
console.error(`${file}: ${missing.length ? `Missing keys: ${missing.join(', ')}` : ''}${extra.length ? ` Extra keys: ${extra.join(', ')}` : ''}`);
19+
}
20+
});
21+
22+
process.exit(hasError ? 1 : 0);

0 commit comments

Comments
 (0)