Skip to content

Instantly share code, notes, and snippets.

@Grohden
Created May 16, 2019 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grohden/9b5c8db97280b4be0bbd1e3234a1f3ed to your computer and use it in GitHub Desktop.
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
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