const path = require('path'); const fs = require('fs'); const argv = require('minimist')(process.argv.slice(2)); var readlineSync = require('readline-sync'); const root = path.resolve(__dirname+"/../config/locales"); const generated = require(root+"/generated/en.json")['en']; const ALLOWED_LANG = ['fr']; let langs = argv.lang.split(','); langs.forEach(function(lang) { if (ALLOWED_LANG.indexOf(lang) === -1) { return; } let localePath = root+"/"+lang+".json"; let locale = {}; locale[lang] = {}; try { locale = require(localePath); } catch(exception ) { console.log("New translation into : "+lang); } Object.keys(generated).forEach(function(word) { //If word hasn't already been translated if (!(word in locale[lang])) { console.log("New word to translate into "+lang); let translation = readlineSync.question('+ '+generated[word]+" : ", { encoding : 'utf-8' }); locale[lang][word] = translation; } }); let localeWords = Object.keys(locale[lang]); let generatedWords = Object.keys(generated); //Tidy locale file to remove useless translated words let data = {} localeWords.forEach(function(word) { if (generatedWords.indexOf(word) !== -1) { data[word] = locale[lang][word] } }); locale[lang] = data; fs.writeFile(localePath, JSON.stringify(locale), function(err) { console.log("en -> "+lang); }); }) // dir.readFiles(root, { // exclude : ['generated'] // }, function(err, content, next) { // // let locale = JSON.parse(content); // let lang = Object.keys(locale)[0]; // // if (lang === "fr") { // // let newLocale = Object.assign({}, generated, locale[lang]); // let data = {}; // data[lang] = newLocale; // // fs.writeFile(root+"/"+lang+".json", JSON.stringify(data), function(err) { // console.log("en -> "+lang); // }); // // } else { // // } // // next(); // // }, function(err, files) { // //console.log(files); // });