Created
March 31, 2022 12:52
-
-
Save mehmetcanker/f7aba358b3efeb31f61cac7291988e64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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