Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
try {
const responseArray = await translationServiceClient.translateText(request);
msg.payload = responseArray[0];
node.send(msg);
}
catch(e) {
console.log(e);
}
} // Input
// We must have EITHER credentials or a keyFilename. If neither are supplied, that
// is an error. If both are supplied, then credentials will be used.
if (credentials) {
translationServiceClient = new translate.v3beta1.TranslationServiceClient({
"credentials": credentials
});
} else if (keyFilename) {
translationServiceClient = new translate.v3beta1.TranslationServiceClient({
"keyFilename": keyFilename
});
} else {
translationServiceClient = new translate.v3beta1.TranslationServiceClient({});
}
node.on("input", Input);
} // TranslateNode
function main(
projectId = 'YOUR_PROJECT_ID',
location = 'global',
text = 'text to translate'
) {
// [START translate_detect_language_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function detectLanguage() {
// Construct request
const request = {
parent: translationClient.locationPath(projectId, location),
content: text,
};
// Run request
const [response] = await translationClient.detectLanguage(request);
console.log(`Detected Languages:`);
for (const language of response.languages) {
function main(projectId = 'YOUR_PROJECT_ID', location = 'global') {
// [START translate_list_language_names_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function listLanguages() {
// Construct request
const request = {
parent: translationClient.locationPath(projectId, location),
displayLanguageCode: 'fr',
};
// Run request
const [response] = await translationClient.getSupportedLanguages(request);
console.log(`Supported languages:`);
for (const language of response.languages) {
function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') {
// [START translate_list_glossary_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function listGlossaries() {
// Construct request
const request = {
parent: translationClient.locationPath(projectId, location),
};
// Run request
const [response] = await translationClient.listGlossaries(request);
for (const glossary of response) {
console.log(`Name: ${glossary.name}`);
console.log(`Entry count: ${glossary.entryCount}`);
function main(
projectId = 'YOUR_PROJECT_ID',
location = 'us-central1',
glossaryId = 'glossary-id'
) {
// [START translate_delete_glossary_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function deleteGlossary() {
// Construct request
const name = translationClient.glossaryPath(
projectId,
location,
glossaryId
);
const request = {
parent: translationClient.locationPath(projectId, location),
name: name,
};
function main(
projectId = 'YOUR_PROJECT_ID',
location = 'us-central1',
glossaryId = 'glossary-id'
) {
// [START translate_create_glossary_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function createGlossary() {
// Construct glossary
const glossary = {
languageCodesSet: {
languageCodes: ['en', 'es'],
},
inputConfig: {
gcsSource: {
inputUri: 'gs://cloud-samples-data/translation/glossary.csv',
},
},
name: translationClient.glossaryPath(projectId, location, glossaryId),
function main(
projectId = 'YOUR_PROJECT_ID',
location = 'us-central1',
glossaryId = 'glossary-id'
) {
// [START translate_get_glossary_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function getGlossary() {
// Construct request
const name = translationClient.glossaryPath(
projectId,
location,
glossaryId
);
const request = {
parent: translationClient.locationPath(projectId, location),
name: name,
};
function main(
projectId = 'YOUR_PROJECT_ID',
location = 'us-central1',
inputUri = 'gs://cloud-samples-data/translation/text.txt',
outputUri = 'gs://YOUR_PROJECT_ID/translation/BATCH_TRANSLATION_OUTPUT/'
) {
// [START translate_batch_translate_text_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const text = 'text to translate';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function batchTranslateText() {
// Construct request
const request = {
parent: translationClient.locationPath(projectId, location),
sourceLanguageCode: 'en-US',
targetLanguageCodes: ['sr-Latn'],
inputConfigs: [
{
mimeType: 'text/plain', // mime types: text/plain, text/html
gcsSource: {
inputUri: inputUri,
},
},
function main(
projectId = 'YOUR_PROJECT_ID',
location = 'global',
text = 'text to translate'
) {
// [START translate_translate_text_beta]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'global';
// const text = 'text to translate';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
async function translateText() {
// Construct request
const request = {
parent: translationClient.locationPath(projectId, location),
contents: [text],
mimeType: 'text/plain', // mime types: text/plain, text/html
sourceLanguageCode: 'en-US',
targetLanguageCode: 'sr-Latn',
};
// Run request
const [response] = await translationClient.translateText(request);
async function main(
projectId = process.env.GCLOUD_PROJECT, // Your GCP Project Id
inFile = 'resources/example.png',
outFile = 'resources/example.mp3',
glossaryLangs = ['fr', 'en'],
glossaryName = 'bistro-glossary',
glossaryUri = 'gs://cloud-samples-data/translation/bistro_glossary.csv'
) {
// [START translate_hybrid_imports]
// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');
const translate = require('@google-cloud/translate').v3beta1;
const vision = require('@google-cloud/vision');
// Import other required libraries
const fs = require('fs');
//const escape = require('escape-html');
const util = require('util');
// [END translate_hybrid_imports]
// [START translate_hybrid_vision]
/**
* Detects text in an image file
*
* ARGS
* inputFile: path to image file
* RETURNS
* string of text detected in the input image