This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
53 lines (41 loc) · 1.81 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require("fs");
const path = require("path");
const readme = JSON.parse(fs.readFileSync(path.join(__dirname, "en", "readme.json"), "utf-8"));
const translations = JSON.parse(fs.readFileSync(path.join(__dirname, "en", "translations.json"), "utf-8"));
let error = false;
const wildcard = (str) => ((str ?? "").match(/{\d+}/g) ?? []).length;
for(const folder of fs.readdirSync(__dirname).filter(f => !f.includes('.') && f !== "en")){
/* readme */ {
const obj = JSON.parse(fs.readFileSync(path.join(__dirname, folder, "readme.json"), "utf-8"));
for(const key of Object.keys(readme)){
if(!Object.keys(obj).includes(key)){
console.error(`[${folder}] Missing README translation for '${key}'`);
error = true;
continue;
}
const [wcO, wcT] = [wildcard(obj[key]), wildcard(readme[key])];
if(wcO !== wcT){
console.error(`[${folder}] '${key}' has incorrect amount of placeholders (${wcO} ≠ ${wcT})`);
error = true;
continue;
}
}
}
/* translations */ {
const obj = JSON.parse(fs.readFileSync(path.join(__dirname, folder, "translations.json"), "utf-8"));
for(const key of Object.keys(translations)){
if(!Object.keys(obj).includes(key)){
console.error(`[${folder}] Missing translation for '${key}'`);
error = true;
continue;
}
const [wcO, wcT] = [wildcard(obj[key]), wildcard(translations[key])];
if(wcO !== wcT){
console.error(`[${folder}] '${key}' has incorrect amount of placeholders (${wcO} ≠ ${wcT})`);
error = true;
continue;
}
}
}
}
error && process.exit(1);