-
Notifications
You must be signed in to change notification settings - Fork 3
/
localeDiff.js
59 lines (50 loc) · 1.62 KB
/
localeDiff.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
57
58
59
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const languageToCompare = process.argv[2];
// Load reference (en) and target locale
const localeBaseRaw = fs.readFileSync(path.join(__dirname, '/src/i18n/en.json'), 'utf8');
const localeNewRaw = fs.readFileSync(path.join(__dirname, '/src/i18n', languageToCompare + '.json'), 'utf8');
const localeBase = JSON.parse(localeBaseRaw);
const localeNew = JSON.parse(localeNewRaw);
console.clear();
console.log('---- LOCALE DIFF ----');
console.log('');
let newKeys = 0;
let removedKeys = 0;
// Find missing keys
for (let [key, value] of Object.entries(localeBase)) {
if (!localeNew.hasOwnProperty(key)) {
console.log('[' + languageToCompare + '][' + chalk.red('MISSING') + '] "' + key + '": "' + value + '"');
newKeys++;
}
}
// Find removed keys
for (let [key, value] of Object.entries(localeNew)) {
if (!localeBase.hasOwnProperty(key)) {
console.log('[en][' + chalk.blue('REMOVED') + '] "' + key + '": "' + value + '"');
removedKeys++;
}
}
console.log('');
console.log('------ RESULTS ------');
console.log('');
if (newKeys > 0 || removedKeys > 0) {
console.log(
chalk.white('There are ') +
chalk.red(newKeys + ' keys') +
chalk.white(' missing in ') +
chalk.green(languageToCompare) +
chalk.white(' and ') +
chalk.blue(removedKeys + ' keys') +
chalk.white(' which are not present in en anymore.')
)
} else {
console.log(
chalk.green('Language ') +
chalk.white(languageToCompare) +
chalk.green(' is up to date with ') + chalk.white('en')
);
}
console.log('');
console.log('---------------------');