Last active
April 11, 2019 12:01
-
-
Save jgwill/cc1d5610da640bb3fbffd6efefb24bb9 to your computer and use it in GitHub Desktop.
Simple Translation using Google Translate API and NodeJS
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
//Install require an env var with your API keys | |
//export GOOGLE_APPLICATION_CREDENTIALS="/home/jgi/x/etc/mykeys-5oeu3uoeu.json" | |
// Imports the Google Cloud client library | |
const {Translate} = require('@google-cloud/translate'); | |
// Instantiates a client | |
const translate = new Translate({ | |
}); | |
// The text to translate | |
const text = 'Hello, world! There is much more that just saying hello that is possible when you have a creative orientation.'; | |
// The target language | |
const target = 'de'; | |
// Translates some text into Russian | |
translate | |
.translate(text, target) | |
.then(results => { | |
const translation = results[0]; | |
console.log(`Text: ${text}`); | |
console.log(`Translation: ${translation}`); | |
}) | |
.catch(err => { | |
console.error('ERROR:', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment