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

docs: Add Cloud Code tags for API Explorer pilot #712

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions samples/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