Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Translation using Google Translate API and NodeJS
//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
You can’t perform that action at this time.