forked from ArkEcosystem/mobile-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
missing-translations.js
42 lines (36 loc) · 1.29 KB
/
missing-translations.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
const fs = require('fs');
const path = require('path');
const i18nDir = path.join(__dirname, '//src//assets//i18n');
const masterFileName = 'en.json';
const getMissingKeys = (master, slave, missingKeys, pathPrefix) => {
if (!missingKeys) {
missingKeys = [];
}
if (typeof master !== 'object') {
return missingKeys;
}
Object.keys(master).forEach(key => {
const slaveValue = slave ? slave[key] : slave
const pathKey = pathPrefix ? `${pathPrefix}.${key}` : key;
if (!slaveValue) {
missingKeys.push(pathKey);
}
getMissingKeys(master[key], slaveValue, missingKeys, pathKey);
});
return missingKeys;
};
fs.readFile(path.join(i18nDir, masterFileName), 'utf8', (err, masterJson) => {
fs.readdir(i18nDir, (err, files) => {
files.filter(fileName => fileName !== masterFileName).forEach((fileName) => {
fs.readFile(path.join(i18nDir, fileName), 'utf8', (err, json) => {
const missingKeys = getMissingKeys(JSON.parse(masterJson), JSON.parse(json));
if (missingKeys.length) {
console.log(`Missing translations in ${fileName} (${missingKeys.length}):`);
missingKeys.forEach(key => console.log(` ${key}`));
} else {
console.log(`File ${fileName} has no missing translations`);
}
});
});
});
});