How to use the @google-cloud/translate.v3beta1.TranslationServiceClient function in @google-cloud/translate

To help you get started, we’ve selected a few @google-cloud/translate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-translate / samples / hybridGlossaries.js View on Github external
async function translateText(
    text,
    sourceLanguageCode,
    targetLanguageCode,
    projectId,
    glossaryName
  ) {
    // Instantiates a client
    const translationClient = new translate.TranslationServiceClient();
    const glossary = translationClient.glossaryPath(
      projectId,
      'us-central1',
      glossaryName
    );
    const glossaryConfig = {
      glossary: glossary,
    };
    // Construct request
    const request = {
      parent: translationClient.locationPath(projectId, 'us-central1'),
      contents: [text],
      mimeType: 'text/plain', // mime types: text/plain, text/html
      sourceLanguageCode: sourceLanguageCode,
      targetLanguageCode: targetLanguageCode,
      glossaryConfig: glossaryConfig,
github googleapis / nodejs-translate / samples / hybridGlossaries.js View on Github external
async function createGlossary(
    languages,
    projectId,
    glossaryName,
    glossaryUri
  ) {
    // Instantiates a client
    const translationClient = await new translate.TranslationServiceClient();

    // Construct glossary
    const glossary = {
      languageCodesSet: {
        languageCodes: languages,
      },
      inputConfig: {
        gcsSource: {
          inputUri: glossaryUri,
        },
      },
      name: translationClient.glossaryPath(
        projectId,
        'us-central1',
        glossaryName
      ),