Skip to content

Commit

Permalink
Add Cloud Code tags for API Explorer pilot (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
abbycar authored and Ace Nassri committed Nov 17, 2022
1 parent 01fc34b commit 831b712
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions translate/v3/translate_translate_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ function main(
// const location = 'global';
// const text = 'text to translate';

// [START translate_v3_translate_text_0]
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate');
// [END translate_v3_translate_text_0]

// [START translate_v3_translate_text_1]
// Instantiates a client
const translationClient = new TranslationServiceClient();
// [END translate_v3_translate_text_1]

async function translateText() {
// [START translate_v3_translate_text_2]
// Construct request
const request = {
parent: `projects/${projectId}/locations/${location}`,
Expand All @@ -41,13 +47,16 @@ function main(
sourceLanguageCode: 'en',
targetLanguageCode: 'sr-Latn',
};
// [END translate_v3_translate_text_2]

// [START translate_v3_translate_text_3]
// Run request
const [response] = await translationClient.translateText(request);

for (const translation of response.translations) {
console.log(`Translation: ${translation.translatedText}`);
}
// [END translate_v3_translate_text_3]
}

translateText();
Expand Down

0 comments on commit 831b712

Please sign in to comment.