Skip to content

Commit

Permalink
Fail lint when a single translation file has more than one string wit…
Browse files Browse the repository at this point in the history
…h the same key.

This isn't going to catch all duplicates. Duplicates also can still exist between files, and with mismatch cases. That's OK, one thing at a time.
  • Loading branch information
kberg committed Feb 15, 2025
1 parent 1969837 commit b163c99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@
"build:server": "tsc --build src/tsconfig.json",
"build:tests": "tsc --build tests/tsconfig.json",
"clean": "rm -r ./build/ ./src/genfiles/ || true",
"lint": "npm run lint:server && npm run lint:client",
"lint": "npm run lint:server && npm run lint:i18n && npm run lint:client",
"lint:client": "vti diagnostics",
"lint:server": "eslint --cache src tests --ext ts --ext vue",
"lint:i18n": "npx ts-node src/tools/translation_audit.ts",
"lint:fix": "eslint --fix src tests --ext ts --ext vue",
"make:cards": "node build/src/server/tools/export_card_rendering.js",
"make:css": "lessc src/styles/common.less build/styles.css && node src/server/tools/gzip.js",
Expand Down
8 changes: 7 additions & 1 deletion src/tools/translation_audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function parseJson(input: string): MultiMap<string, string> {

const pathToTranslationsDir = path.resolve('src/locales');

let errors = 0;
const dirs = fs.readdirSync(pathToTranslationsDir);
for (const lang of dirs) {
const localeDir = path.join(pathToTranslationsDir, lang);
Expand All @@ -69,10 +70,15 @@ for (const lang of dirs) {
for (const key of results.keys()) {
if (results.get(key)!.length > 1) { // eslint-disable-line @typescript-eslint/no-non-null-assertion
const uniqueCount = new Set(results.get(key)).size;
console.log(filename, key, uniqueCount);
console.log(filename, '[', uniqueCount, '] [', key, ']');
errors++;
}
}
}
}
}

if (errors > 0) {
console.error('Multiple translation strings in the same file. Stopping.');
process.exit(1);
}

0 comments on commit b163c99

Please sign in to comment.