Skip to content

Instantly share code, notes, and snippets.

@qunabu
Last active January 16, 2020 11:58
Show Gist options
  • Save qunabu/ac4d34233005c6fe37ede43026265fb7 to your computer and use it in GitHub Desktop.
Save qunabu/ac4d34233005c6fe37ede43026265fb7 to your computer and use it in GitHub Desktop.
getTranslationApp.js
/** Runs the application */
// INPUT_FILE is a path to json file with input_vars
// TARGET_LANG is langauge code that input_vars should be translated to
// process.env.GKEY is Google API Key generated by `gcloud auth application-default print-access-token`
getJSON(INPUT_FILE) // get data from input file
.then(input_vars => convertToArray(input_vars)) // convert data from object to array
.then(input_arr =>processTranslation(input_arr, TARGET_LANG, process.env.GKEY)) // process the whole array
.then(transl_arr => convertToObject(transl_arr)) // convert data from array to object
.then(output_vars => writeToFile(`translated_${TARGET_LANG}.json`, output_vars)) // saves translated object into file)
.then(filename => console.log(`translation succesfully saved in ${filename}`)) // outputs success
.catch(err => console.error("Error", err)); // shows error in case of any of above fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment