Created
November 7, 2018 08:57
-
-
Save ddikman/a280a72f7e5d3f9a4ab3db95ce025a52 to your computer and use it in GitHub Desktop.
This file contains 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 exec = require('child_process').execSync | |
// SUMMARY: | |
// This simple script uses gtranslate npm cli tool to translate an input file | |
// of countries in json format to another format with translated country names | |
// the expected input would be [ { "country": "name" } ] | |
let inputCountries = JSON.parse(fs.readFileSync('countries.json')) | |
function translate (term) { | |
return exec(`gtranslate --brief --source en --target es ${term}`).toString().trim() | |
} | |
// you can use inputCountries.slice(1, 5) to restrict how many entries to translate | |
var outputCountries = inputCountries.map(country => { | |
return { | |
name: country.country, | |
translation: translate(country.country) | |
} | |
}) | |
process.stdout.write(JSON.stringify(outputCountries)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment