Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

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 committed Aug 24, 2021
1 parent 41062a6 commit d8f03ce
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/v3/translate_translate_text.js
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 d8f03ce

Please sign in to comment.