forked from vegeta999/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslationDiff.js
More file actions
38 lines (29 loc) · 1.21 KB
/
Copy pathtranslationDiff.js
File metadata and controls
38 lines (29 loc) · 1.21 KB
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
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const util = require('util');
// Convert fs.readFile into Promise version of same
const readFile = util.promisify(fs.readFile);
const translationDir = path.resolve(__dirname, '../packages/rocketchat-i18n/i18n/');
async function translationDiff(source, target) {
console.debug('loading translations from', translationDir);
function diffKeys(a, b) {
const diff = {};
Object.keys(a).forEach((key) => {
if (!b[key]) {
diff[key] = a[key];
}
});
return diff;
}
const sourceTranslations = JSON.parse(await readFile(`${ translationDir }/${ source }.i18n.json`, 'utf8'));
const targetTranslations = JSON.parse(await readFile(`${ translationDir }/${ target }.i18n.json`, 'utf8'));
return diffKeys(sourceTranslations, targetTranslations);
}
console.log('Note: You can set the source and target language of the comparison with env-variables SOURCE/TARGET_LANGUAGE');
const sourceLang = process.env.SOURCE_LANGUAGE || 'en';
const targetLang = process.env.TARGET_LANGUAGE || 'de';
translationDiff(sourceLang, targetLang).then((diff) => {
console.log('Diff between', sourceLang, 'and', targetLang);
console.log(JSON.stringify(diff, '', 2));
});