123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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 ALLOWED_LANG = ['fr'];
- let langs = argv.dest.split(',');
- let src = argv.src
- const generated = require(root+"/"+src+".json")[src];
- 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);
- });
- });
|