forked from Authenticator-Extension/Authenticator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.js
33 lines (29 loc) · 1.04 KB
/
i18n.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
// This checks for new stings from _locales/en/messages.json and adds them
// to other translation files. Used by i18n.sh
'use strict';
const fs = require('fs');
function readFile(filename) {
let data = fs.readFileSync(filename);
data = data.toString().replace(/^\uFEFF/, '');
return JSON.parse(data);
}
let strings = readFile('_locales/en/messages.json');
let currentFile;
let missingKeys = [];
fs.readdir('_locales', function(err, items) {
for (let i=0; i<items.length; i++) {
if (items[i] !== 'en') {
currentFile = readFile('_locales/' + items[i] + '/messages.json');
missingKeys = Object.keys(strings).filter(string => !currentFile.hasOwnProperty(string));
if (!missingKeys[0]) {
continue;
}
for (let j=0; j<missingKeys.length; j++) {
currentFile[missingKeys[j]] = strings[missingKeys[j]]
fs.writeFile('_locales/' + items[i] + '/messages.json', JSON.stringify(currentFile, null, 4), (err) => {
if (err) throw err;
})
}
}
}
});