Skip to content

Instantly share code, notes, and snippets.

@mehmetcanker
Created March 31, 2022 12:52
Show Gist options
  • Save mehmetcanker/f7aba358b3efeb31f61cac7291988e64 to your computer and use it in GitHub Desktop.
Save mehmetcanker/f7aba358b3efeb31f61cac7291988e64 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const xlsx = require('node-xlsx');
const _ = require('lodash');
const fileName = './resource.json';
const file = require(fileName);
const translationFile = xlsx.parse(`${__dirname}/translations.xlsx`);
const epvl = _.find(translationFile, { 'name': 'EP validation'});
async function parseFile(){
const epvlRows = epvl.data;
epvlRows.shift();
for(epvlRow of epvlRows){
const translationKey = epvlRow[3]
if(translationKey && translationKey.includes('.')
&& epvlRow[5]){
await writeFile(translationKey, epvlRow[5]);
}
}
}
async function writeFile(key, value) {
file[key] = value;
await fs.writeFile(fileName, JSON.stringify(file), function writeJSON(err) {
if (err) return console.log(err);
console.log(JSON.stringify(file));
console.log('writing to ' + fileName);
});
}
parseFile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment