Created
May 16, 2019 04:56
-
-
Save Grohden/9b5c8db97280b4be0bbd1e3234a1f3ed to your computer and use it in GitHub Desktop.
NodeJs script to read two specific files for translation and write them together for better revision
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 english = require("./english.json").text | |
const portuguese = require("./portuguese.json").text | |
const DEFAULT_KEY = "en-US" | |
const accumlator = {} | |
// Acc the english ones | |
english.reduce((all, value) => { | |
all[value.key] = { | |
"en-US": value[DEFAULT_KEY] | |
} | |
return all | |
}, accumlator) | |
// Acc the portuguese ones | |
portuguese.reduce((all, value) => { | |
all[value.key] = { | |
...(all[value.key] || {}), | |
"pt-BR": value[DEFAULT_KEY] | |
} | |
return all | |
}, accumlator) | |
fs.writeFileSync('for-revision.json', JSON.stringify(accumlator, null, 2), { encoding: 'utf8'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment