forked from killergerbah/asbplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-loc-from-en.js
38 lines (30 loc) · 939 Bytes
/
merge-loc-from-en.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
const path = require('path')
const fs = require('fs')
const localesPath = path.join(__dirname, '../common/locales')
const merge = (a, b) => {
const merged = {...a, ...b};
for (const key of Object.keys(a)) {
if (typeof a[key] !== 'object') {
continue;
}
if (key in b) {
merged[key] = merge(a[key], b[key])
}
}
return merged;
};
fs.readdir(localesPath, (err, files) => {
if (err) {
console.error(error);
}
const enLocale = JSON.parse(fs.readFileSync(`${localesPath}/en.json`));
for (const f of files) {
if (f === 'en.json') {
continue;
}
const localePath = `${localesPath}/${f}`;
const locale = JSON.parse(fs.readFileSync(localePath, 'utf8'));
const mergedLocale = merge(enLocale, locale);
fs.writeFileSync(localePath, JSON.stringify(mergedLocale, null, 4), 'utf8');
}
});