2017-06-12 12:20:50 +02:00
|
|
|
var extract = require('i18n-extract');
|
2017-06-12 12:34:40 +02:00
|
|
|
const fs = require('fs');
|
2017-06-12 12:20:50 +02:00
|
|
|
|
2017-06-12 12:34:40 +02:00
|
|
|
var path = '../app/dist/locales/en.json';
|
|
|
|
|
|
|
|
fs.writeFile(path, '{}', 'utf8', function(err) {
|
|
|
|
if(err) {
|
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
var enLocale = require(path);
|
2017-06-12 12:20:50 +02:00
|
|
|
|
2017-06-12 12:34:40 +02:00
|
|
|
const keys = extract.extractFromFiles(['js/**/*.{js,jsx}'], {
|
2017-06-12 12:20:50 +02:00
|
|
|
marker: '__',
|
|
|
|
});
|
|
|
|
|
|
|
|
let reports = [];
|
|
|
|
reports = reports.concat(extract.findMissing(enLocale, keys));
|
|
|
|
|
|
|
|
if (reports.length > 0) {
|
2017-06-12 12:34:40 +02:00
|
|
|
fs.readFile(path, 'utf8', function readFileCallback(err, data){
|
2017-06-12 12:20:50 +02:00
|
|
|
if (err){
|
|
|
|
console.log(err);
|
|
|
|
} else {
|
|
|
|
localeObj = JSON.parse(data);
|
|
|
|
|
|
|
|
for (var i = 0; i < reports.length; i++) {
|
2017-06-12 21:18:20 +02:00
|
|
|
// no need to care for other types than MISSING because starting file will always be empty
|
2017-06-12 12:20:50 +02:00
|
|
|
if (reports[i].type === 'MISSING') {
|
|
|
|
localeObj[reports[i].key] = reports[i].key;
|
2017-06-12 21:18:20 +02:00
|
|
|
}
|
2017-06-12 12:20:50 +02:00
|
|
|
}
|
|
|
|
|
2017-06-12 21:18:20 +02:00
|
|
|
var json = JSON.stringify(localeObj, null, '\t'); //convert it back to json-string
|
2017-06-12 12:34:40 +02:00
|
|
|
fs.writeFile(path, json, 'utf8', function callback(err) {
|
2017-06-12 12:20:50 +02:00
|
|
|
if (err) throw err;
|
2017-06-12 21:18:20 +02:00
|
|
|
console.log('Extracted all strings!');
|
2017-06-12 12:20:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-06-12 12:34:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-12 12:20:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|