forked from polywock/globalSpeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplaceLocale.js
56 lines (44 loc) · 1.24 KB
/
replaceLocale.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
54
55
56
// Test to make sure all locales have the required strings.
const { readFileSync } = require("fs")
const { exit } = require("process")
const locales = ["en", "it", "es", "ja", "ko", "pt_BR", "ru", "tr", "zh_CN", "zh_TW"]
let targetLeaves;
for (let locale of locales) {
let leaves;
try {
leaves = getLeafs(JSON.parse(readFileSync(`./static/locales/${locale}.json`, {encoding: "utf8"})))
} catch (err) {
console.log("Could not parse", locale, leaves)
exit()
}
if (!targetLeaves) {
targetLeaves = leaves;
continue
}
const omitted = targetLeaves.filter(v => !leaves.includes(v))
const extra = leaves.filter(v => !targetLeaves.includes(v))
if (omitted.length) {
console.log("OMITTED", "\n=========")
omitted.forEach(v => console.log(v))
}
if (extra.length) {
console.log("EXTRA", "\n=========")
extra.forEach(v => console.log(v))
}
if (omitted.length + extra.length ) {
console.log("FIX", locale)
exit()
}
}
console.log("ALL GOOD!")
function getLeafs(obj, ctx = []) {
const leafs = []
for (let [k, v] of Object.entries(obj)) {
if (typeof v === "object") {
leafs.push(...getLeafs(v, [...ctx, k]))
} else {
leafs.push([...ctx, k].join('.'))
}
}
return leafs
}