Class v3.TranslationServiceClient

Provides natural language translation operations. v3

Package

@google-cloud/translate

Constructors

(constructor)(opts)

constructor(opts?: ClientOptions);

Construct an instance of TranslationServiceClient.

Parameter
NameDescription
opts ClientOptions

Properties

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

operationsClient

operationsClient: gax.OperationsClient;

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

translationServiceStub

translationServiceStub?: Promise<{
        [name: string]: Function;
    }>;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

batchTranslateDocument(request, options)

batchTranslateDocument(request?: protos.google.cloud.translation.v3.IBatchTranslateDocumentRequest, options?: CallOptions): Promise<[LROperation<protos.google.cloud.translation.v3.IBatchTranslateDocumentResponse, protos.google.cloud.translation.v3.IBatchTranslateDocumentMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>;

Translates a large volume of document in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location.

This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IBatchTranslateDocumentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[LROperation<protos.google.cloud.translation.v3.IBatchTranslateDocumentResponse, protos.google.cloud.translation.v3.IBatchTranslateDocumentMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Location to make a regional call.
   *  Format: `projects/{project-number-or-id}/locations/{location-id}`.
   *  The `global` location is not supported for batch translation.
   *  Only AutoML Translation models or glossaries within the same region (have
   *  the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
   *  error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Required. The BCP-47 language code of the input document if known, for
   *  example, "en-US" or "sr-Latn". Supported language codes are listed in
   *  Language Support (https://cloud.google.com/translate/docs/languages).
   */
  // const sourceLanguageCode = 'abc123'
  /**
   *  Required. The BCP-47 language code to use for translation of the input
   *  document. Specify up to 10 language codes here.
   */
  // const targetLanguageCodes = 'abc123'
  /**
   *  Required. Input configurations.
   *  The total number of files matched should be <= 100.="" *="" the="" total="" content="" size="" to="" translate="" should="" be=""><= 100m="" unicode="" codepoints.="" *="" the="" files="" must="" use="" utf-8="" encoding.="" */="" const="" inputconfigs="1234" *="" *="" required.="" output="" configuration.="" *="" if="" 2="" input="" configs="" match="" to="" the="" same="" file="" (that="" is,="" same="" input="" path),="" *="" we="" don't="" generate="" output="" for="" duplicate="" inputs.="" */="" const="" outputconfig="{}" *="" *="" optional.="" the="" models="" to="" use="" for="" translation.="" map's="" key="" is="" target="" language="" *="" code.="" map's="" value="" is="" the="" model="" name.="" value="" can="" be="" a="" built-in="" general="" model,="" *="" or="" an="" automl="" translation="" model.="" *="" the="" value="" format="" depends="" on="" model="" type:="" *="" -="" automl="" translation="" models:="" *="" `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`="" *="" -="" general="" (built-in)="" models:="" *="" `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,="" *="" if="" the="" map="" is="" empty="" or="" a="" specific="" model="" is="" *="" not="" requested="" for="" a="" language="" pair,="" then="" default="" google="" model="" (nmt)="" is="" used.="" */="" const="" models="1234" *="" *="" optional.="" glossaries="" to="" be="" applied.="" it's="" keyed="" by="" target="" language="" code.="" */="" const="" glossaries="1234" *="" *="" optional.="" file="" format="" conversion="" map="" to="" be="" applied="" to="" all="" input="" files.="" *="" map's="" key="" is="" the="" original="" mime_type.="" map's="" value="" is="" the="" target="" mime_type="" of="" *="" translated="" documents.="" *="" supported="" file="" format="" conversion="" includes:="" *="" -="" `application/pdf`="" to="" *="" `application/vnd.openxmlformats-officedocument.wordprocessingml.document`="" *="" if="" nothing="" specified,="" output="" files="" will="" be="" in="" the="" same="" format="" as="" the="" *="" original="" file.="" */="" const="" formatconversions="1234" imports="" the="" translation="" library="" const="" {translationserviceclient}="require('@google-cloud/translate').v3;" instantiates="" a="" client="" const="" translationclient="new" translationserviceclient();="" async="" function="" callbatchtranslatedocument()="" {="" construct="" request="" const="" request="{" parent,="" sourcelanguagecode,="" targetlanguagecodes,="" inputconfigs,="" outputconfig,="" };="" run="" request="" const="" [operation]="await" translationclient.batchtranslatedocument(request);="" const="" [response]="await" operation.promise();="" console.log(response);="" }="" callbatchtranslatedocument();="">

batchTranslateDocument(request, options, callback)

batchTranslateDocument(request: protos.google.cloud.translation.v3.IBatchTranslateDocumentRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateDocumentResponse, protos.google.cloud.translation.v3.IBatchTranslateDocumentMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IBatchTranslateDocumentRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateDocumentResponse, protos.google.cloud.translation.v3.IBatchTranslateDocumentMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchTranslateDocument(request, callback)

batchTranslateDocument(request: protos.google.cloud.translation.v3.IBatchTranslateDocumentRequest, callback: Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateDocumentResponse, protos.google.cloud.translation.v3.IBatchTranslateDocumentMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IBatchTranslateDocumentRequest
callback Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateDocumentResponse, protos.google.cloud.translation.v3.IBatchTranslateDocumentMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchTranslateText(request, options)

batchTranslateText(request?: protos.google.cloud.translation.v3.IBatchTranslateTextRequest, options?: CallOptions): Promise<[LROperation<protos.google.cloud.translation.v3.IBatchTranslateResponse, protos.google.cloud.translation.v3.IBatchTranslateMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>;

Translates a large volume of text in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location.

This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IBatchTranslateTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[LROperation<protos.google.cloud.translation.v3.IBatchTranslateResponse, protos.google.cloud.translation.v3.IBatchTranslateMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Location to make a call. Must refer to a caller's project.
   *  Format: `projects/{project-number-or-id}/locations/{location-id}`.
   *  The `global` location is not supported for batch translation.
   *  Only AutoML Translation models or glossaries within the same region (have
   *  the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
   *  error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Required. Source language code.
   */
  // const sourceLanguageCode = 'abc123'
  /**
   *  Required. Specify up to 10 language codes here.
   */
  // const targetLanguageCodes = 'abc123'
  /**
   *  Optional. The models to use for translation. Map's key is target language
   *  code. Map's value is model name. Value can be a built-in general model,
   *  or an AutoML Translation model.
   *  The value format depends on model type:
   *  - AutoML Translation models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
   *  - General (built-in) models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
   *  If the map is empty or a specific model is
   *  not requested for a language pair, then default google model (nmt) is used.
   */
  // const models = 1234
  /**
   *  Required. Input configurations.
   *  The total number of files matched should be <= 100.="" *="" the="" total="" content="" size="" should="" be=""><= 100m="" unicode="" codepoints.="" *="" the="" files="" must="" use="" utf-8="" encoding.="" */="" const="" inputconfigs="1234" *="" *="" required.="" output="" configuration.="" *="" if="" 2="" input="" configs="" match="" to="" the="" same="" file="" (that="" is,="" same="" input="" path),="" *="" we="" don't="" generate="" output="" for="" duplicate="" inputs.="" */="" const="" outputconfig="{}" *="" *="" optional.="" glossaries="" to="" be="" applied="" for="" translation.="" *="" it's="" keyed="" by="" target="" language="" code.="" */="" const="" glossaries="1234" *="" *="" optional.="" the="" labels="" with="" user-defined="" metadata="" for="" the="" request.="" *="" label="" keys="" and="" values="" can="" be="" no="" longer="" than="" 63="" characters="" *="" (unicode="" codepoints),="" can="" only="" contain="" lowercase="" letters,="" numeric="" *="" characters,="" underscores="" and="" dashes.="" international="" characters="" are="" allowed.="" *="" label="" values="" are="" optional.="" label="" keys="" must="" start="" with="" a="" letter.="" *="" see="" https://cloud.google.com/translate/docs/advanced/labels="" for="" more="" *="" information.="" */="" const="" labels="1234" imports="" the="" translation="" library="" const="" {translationserviceclient}="require('@google-cloud/translate').v3;" instantiates="" a="" client="" const="" translationclient="new" translationserviceclient();="" async="" function="" callbatchtranslatetext()="" {="" construct="" request="" const="" request="{" parent,="" sourcelanguagecode,="" targetlanguagecodes,="" inputconfigs,="" outputconfig,="" };="" run="" request="" const="" [operation]="await" translationclient.batchtranslatetext(request);="" const="" [response]="await" operation.promise();="" console.log(response);="" }="" callbatchtranslatetext();="">

batchTranslateText(request, options, callback)

batchTranslateText(request: protos.google.cloud.translation.v3.IBatchTranslateTextRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateResponse, protos.google.cloud.translation.v3.IBatchTranslateMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IBatchTranslateTextRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateResponse, protos.google.cloud.translation.v3.IBatchTranslateMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchTranslateText(request, callback)

batchTranslateText(request: protos.google.cloud.translation.v3.IBatchTranslateTextRequest, callback: Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateResponse, protos.google.cloud.translation.v3.IBatchTranslateMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IBatchTranslateTextRequest
callback Callback<LROperation<protos.google.cloud.translation.v3.IBatchTranslateResponse, protos.google.cloud.translation.v3.IBatchTranslateMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

checkBatchTranslateDocumentProgress(name)

checkBatchTranslateDocumentProgress(name: string): Promise<LROperation<protos.google.cloud.translation.v3.BatchTranslateDocumentResponse, protos.google.cloud.translation.v3.BatchTranslateDocumentMetadata>>;

Check the status of the long running operation returned by batchTranslateDocument().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.translation.v3.BatchTranslateDocumentResponse, protos.google.cloud.translation.v3.BatchTranslateDocumentMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Location to make a regional call.
   *  Format: `projects/{project-number-or-id}/locations/{location-id}`.
   *  The `global` location is not supported for batch translation.
   *  Only AutoML Translation models or glossaries within the same region (have
   *  the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
   *  error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Required. The BCP-47 language code of the input document if known, for
   *  example, "en-US" or "sr-Latn". Supported language codes are listed in
   *  Language Support (https://cloud.google.com/translate/docs/languages).
   */
  // const sourceLanguageCode = 'abc123'
  /**
   *  Required. The BCP-47 language code to use for translation of the input
   *  document. Specify up to 10 language codes here.
   */
  // const targetLanguageCodes = 'abc123'
  /**
   *  Required. Input configurations.
   *  The total number of files matched should be <= 100.="" *="" the="" total="" content="" size="" to="" translate="" should="" be=""><= 100m="" unicode="" codepoints.="" *="" the="" files="" must="" use="" utf-8="" encoding.="" */="" const="" inputconfigs="1234" *="" *="" required.="" output="" configuration.="" *="" if="" 2="" input="" configs="" match="" to="" the="" same="" file="" (that="" is,="" same="" input="" path),="" *="" we="" don't="" generate="" output="" for="" duplicate="" inputs.="" */="" const="" outputconfig="{}" *="" *="" optional.="" the="" models="" to="" use="" for="" translation.="" map's="" key="" is="" target="" language="" *="" code.="" map's="" value="" is="" the="" model="" name.="" value="" can="" be="" a="" built-in="" general="" model,="" *="" or="" an="" automl="" translation="" model.="" *="" the="" value="" format="" depends="" on="" model="" type:="" *="" -="" automl="" translation="" models:="" *="" `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`="" *="" -="" general="" (built-in)="" models:="" *="" `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,="" *="" if="" the="" map="" is="" empty="" or="" a="" specific="" model="" is="" *="" not="" requested="" for="" a="" language="" pair,="" then="" default="" google="" model="" (nmt)="" is="" used.="" */="" const="" models="1234" *="" *="" optional.="" glossaries="" to="" be="" applied.="" it's="" keyed="" by="" target="" language="" code.="" */="" const="" glossaries="1234" *="" *="" optional.="" file="" format="" conversion="" map="" to="" be="" applied="" to="" all="" input="" files.="" *="" map's="" key="" is="" the="" original="" mime_type.="" map's="" value="" is="" the="" target="" mime_type="" of="" *="" translated="" documents.="" *="" supported="" file="" format="" conversion="" includes:="" *="" -="" `application/pdf`="" to="" *="" `application/vnd.openxmlformats-officedocument.wordprocessingml.document`="" *="" if="" nothing="" specified,="" output="" files="" will="" be="" in="" the="" same="" format="" as="" the="" *="" original="" file.="" */="" const="" formatconversions="1234" imports="" the="" translation="" library="" const="" {translationserviceclient}="require('@google-cloud/translate').v3;" instantiates="" a="" client="" const="" translationclient="new" translationserviceclient();="" async="" function="" callbatchtranslatedocument()="" {="" construct="" request="" const="" request="{" parent,="" sourcelanguagecode,="" targetlanguagecodes,="" inputconfigs,="" outputconfig,="" };="" run="" request="" const="" [operation]="await" translationclient.batchtranslatedocument(request);="" const="" [response]="await" operation.promise();="" console.log(response);="" }="" callbatchtranslatedocument();="">

checkBatchTranslateTextProgress(name)

checkBatchTranslateTextProgress(name: string): Promise<LROperation<protos.google.cloud.translation.v3.BatchTranslateResponse, protos.google.cloud.translation.v3.BatchTranslateMetadata>>;

Check the status of the long running operation returned by batchTranslateText().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.translation.v3.BatchTranslateResponse, protos.google.cloud.translation.v3.BatchTranslateMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Location to make a call. Must refer to a caller's project.
   *  Format: `projects/{project-number-or-id}/locations/{location-id}`.
   *  The `global` location is not supported for batch translation.
   *  Only AutoML Translation models or glossaries within the same region (have
   *  the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
   *  error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Required. Source language code.
   */
  // const sourceLanguageCode = 'abc123'
  /**
   *  Required. Specify up to 10 language codes here.
   */
  // const targetLanguageCodes = 'abc123'
  /**
   *  Optional. The models to use for translation. Map's key is target language
   *  code. Map's value is model name. Value can be a built-in general model,
   *  or an AutoML Translation model.
   *  The value format depends on model type:
   *  - AutoML Translation models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
   *  - General (built-in) models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
   *  If the map is empty or a specific model is
   *  not requested for a language pair, then default google model (nmt) is used.
   */
  // const models = 1234
  /**
   *  Required. Input configurations.
   *  The total number of files matched should be <= 100.="" *="" the="" total="" content="" size="" should="" be=""><= 100m="" unicode="" codepoints.="" *="" the="" files="" must="" use="" utf-8="" encoding.="" */="" const="" inputconfigs="1234" *="" *="" required.="" output="" configuration.="" *="" if="" 2="" input="" configs="" match="" to="" the="" same="" file="" (that="" is,="" same="" input="" path),="" *="" we="" don't="" generate="" output="" for="" duplicate="" inputs.="" */="" const="" outputconfig="{}" *="" *="" optional.="" glossaries="" to="" be="" applied="" for="" translation.="" *="" it's="" keyed="" by="" target="" language="" code.="" */="" const="" glossaries="1234" *="" *="" optional.="" the="" labels="" with="" user-defined="" metadata="" for="" the="" request.="" *="" label="" keys="" and="" values="" can="" be="" no="" longer="" than="" 63="" characters="" *="" (unicode="" codepoints),="" can="" only="" contain="" lowercase="" letters,="" numeric="" *="" characters,="" underscores="" and="" dashes.="" international="" characters="" are="" allowed.="" *="" label="" values="" are="" optional.="" label="" keys="" must="" start="" with="" a="" letter.="" *="" see="" https://cloud.google.com/translate/docs/advanced/labels="" for="" more="" *="" information.="" */="" const="" labels="1234" imports="" the="" translation="" library="" const="" {translationserviceclient}="require('@google-cloud/translate').v3;" instantiates="" a="" client="" const="" translationclient="new" translationserviceclient();="" async="" function="" callbatchtranslatetext()="" {="" construct="" request="" const="" request="{" parent,="" sourcelanguagecode,="" targetlanguagecodes,="" inputconfigs,="" outputconfig,="" };="" run="" request="" const="" [operation]="await" translationclient.batchtranslatetext(request);="" const="" [response]="await" operation.promise();="" console.log(response);="" }="" callbatchtranslatetext();="">

checkCreateGlossaryProgress(name)

checkCreateGlossaryProgress(name: string): Promise<LROperation<protos.google.cloud.translation.v3.Glossary, protos.google.cloud.translation.v3.CreateGlossaryMetadata>>;

Check the status of the long running operation returned by createGlossary().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.translation.v3.Glossary, protos.google.cloud.translation.v3.CreateGlossaryMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The project name.
   */
  // const parent = 'abc123'
  /**
   *  Required. The glossary to create.
   */
  // const glossary = {}

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callCreateGlossary() {
    // Construct request
    const request = {
      parent,
      glossary,
    };

    // Run request
    const [operation] = await translationClient.createGlossary(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callCreateGlossary();

checkDeleteGlossaryProgress(name)

checkDeleteGlossaryProgress(name: string): Promise<LROperation<protos.google.cloud.translation.v3.DeleteGlossaryResponse, protos.google.cloud.translation.v3.DeleteGlossaryMetadata>>;

Check the status of the long running operation returned by deleteGlossary().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.translation.v3.DeleteGlossaryResponse, protos.google.cloud.translation.v3.DeleteGlossaryMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The name of the glossary to delete.
   */
  // const name = 'abc123'

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callDeleteGlossary() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await translationClient.deleteGlossary(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callDeleteGlossary();

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
TypeDescription
Promise<void>

{Promise} A promise that resolves when the client is closed.

createGlossary(request, options)

createGlossary(request?: protos.google.cloud.translation.v3.ICreateGlossaryRequest, options?: CallOptions): Promise<[LROperation<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.ICreateGlossaryMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>;

Creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn't exist.

Parameters
NameDescription
request protos.google.cloud.translation.v3.ICreateGlossaryRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[LROperation<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.ICreateGlossaryMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The project name.
   */
  // const parent = 'abc123'
  /**
   *  Required. The glossary to create.
   */
  // const glossary = {}

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callCreateGlossary() {
    // Construct request
    const request = {
      parent,
      glossary,
    };

    // Run request
    const [operation] = await translationClient.createGlossary(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callCreateGlossary();

createGlossary(request, options, callback)

createGlossary(request: protos.google.cloud.translation.v3.ICreateGlossaryRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.ICreateGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.ICreateGlossaryRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.ICreateGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

createGlossary(request, callback)

createGlossary(request: protos.google.cloud.translation.v3.ICreateGlossaryRequest, callback: Callback<LROperation<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.ICreateGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.ICreateGlossaryRequest
callback Callback<LROperation<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.ICreateGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

deleteGlossary(request, options)

deleteGlossary(request?: protos.google.cloud.translation.v3.IDeleteGlossaryRequest, options?: CallOptions): Promise<[LROperation<protos.google.cloud.translation.v3.IDeleteGlossaryResponse, protos.google.cloud.translation.v3.IDeleteGlossaryMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>;

Deletes a glossary, or cancels glossary construction if the glossary isn't created yet. Returns NOT_FOUND, if the glossary doesn't exist.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IDeleteGlossaryRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[LROperation<protos.google.cloud.translation.v3.IDeleteGlossaryResponse, protos.google.cloud.translation.v3.IDeleteGlossaryMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The name of the glossary to delete.
   */
  // const name = 'abc123'

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callDeleteGlossary() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await translationClient.deleteGlossary(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callDeleteGlossary();

deleteGlossary(request, options, callback)

deleteGlossary(request: protos.google.cloud.translation.v3.IDeleteGlossaryRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.translation.v3.IDeleteGlossaryResponse, protos.google.cloud.translation.v3.IDeleteGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IDeleteGlossaryRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.translation.v3.IDeleteGlossaryResponse, protos.google.cloud.translation.v3.IDeleteGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

deleteGlossary(request, callback)

deleteGlossary(request: protos.google.cloud.translation.v3.IDeleteGlossaryRequest, callback: Callback<LROperation<protos.google.cloud.translation.v3.IDeleteGlossaryResponse, protos.google.cloud.translation.v3.IDeleteGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IDeleteGlossaryRequest
callback Callback<LROperation<protos.google.cloud.translation.v3.IDeleteGlossaryResponse, protos.google.cloud.translation.v3.IDeleteGlossaryMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

detectLanguage(request, options)

detectLanguage(request?: protos.google.cloud.translation.v3.IDetectLanguageRequest, options?: CallOptions): Promise<[protos.google.cloud.translation.v3.IDetectLanguageResponse, protos.google.cloud.translation.v3.IDetectLanguageRequest | undefined, {} | undefined]>;

Detects the language of text within a request.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IDetectLanguageRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.translation.v3.IDetectLanguageResponse, protos.google.cloud.translation.v3.IDetectLanguageRequest | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [DetectLanguageResponse]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Project or location to make a call. Must refer to a caller's
   *  project.
   *  Format: `projects/{project-number-or-id}/locations/{location-id}` or
   *  `projects/{project-number-or-id}`.
   *  For global calls, use `projects/{project-number-or-id}/locations/global` or
   *  `projects/{project-number-or-id}`.
   *  Only models within the same region (has same location-id) can be used.
   *  Otherwise an INVALID_ARGUMENT (400) error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Optional. The language detection model to be used.
   *  Format:
   *  `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}`
   *  Only one language detection model is currently supported:
   *  `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`.
   *  If not specified, the default model is used.
   */
  // const model = 'abc123'
  /**
   *  The content of the input stored as a string.
   */
  // const content = 'abc123'
  /**
   *  Optional. The format of the source text, for example, "text/html",
   *  "text/plain". If left blank, the MIME type defaults to "text/html".
   */
  // const mimeType = 'abc123'
  /**
   *  Optional. The labels with user-defined metadata for the request.
   *  Label keys and values can be no longer than 63 characters
   *  (Unicode codepoints), can only contain lowercase letters, numeric
   *  characters, underscores and dashes. International characters are allowed.
   *  Label values are optional. Label keys must start with a letter.
   *  See https://cloud.google.com/translate/docs/advanced/labels for more
   *  information.
   */
  // const labels = 1234

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callDetectLanguage() {
    // Construct request
    const request = {
      parent,
    };

    // Run request
    const response = await translationClient.detectLanguage(request);
    console.log(response);
  }

  callDetectLanguage();

detectLanguage(request, options, callback)

detectLanguage(request: protos.google.cloud.translation.v3.IDetectLanguageRequest, options: CallOptions, callback: Callback<protos.google.cloud.translation.v3.IDetectLanguageResponse, protos.google.cloud.translation.v3.IDetectLanguageRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IDetectLanguageRequest
options CallOptions
callback Callback<protos.google.cloud.translation.v3.IDetectLanguageResponse, protos.google.cloud.translation.v3.IDetectLanguageRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

detectLanguage(request, callback)

detectLanguage(request: protos.google.cloud.translation.v3.IDetectLanguageRequest, callback: Callback<protos.google.cloud.translation.v3.IDetectLanguageResponse, protos.google.cloud.translation.v3.IDetectLanguageRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IDetectLanguageRequest
callback Callback<protos.google.cloud.translation.v3.IDetectLanguageResponse, protos.google.cloud.translation.v3.IDetectLanguageRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getGlossary(request, options)

getGlossary(request?: protos.google.cloud.translation.v3.IGetGlossaryRequest, options?: CallOptions): Promise<[protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.IGetGlossaryRequest | undefined, {} | undefined]>;

Gets a glossary. Returns NOT_FOUND, if the glossary doesn't exist.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IGetGlossaryRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.IGetGlossaryRequest | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [Glossary]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The name of the glossary to retrieve.
   */
  // const name = 'abc123'

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callGetGlossary() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const response = await translationClient.getGlossary(request);
    console.log(response);
  }

  callGetGlossary();

getGlossary(request, options, callback)

getGlossary(request: protos.google.cloud.translation.v3.IGetGlossaryRequest, options: CallOptions, callback: Callback<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.IGetGlossaryRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IGetGlossaryRequest
options CallOptions
callback Callback<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.IGetGlossaryRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getGlossary(request, callback)

getGlossary(request: protos.google.cloud.translation.v3.IGetGlossaryRequest, callback: Callback<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.IGetGlossaryRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IGetGlossaryRequest
callback Callback<protos.google.cloud.translation.v3.IGlossary, protos.google.cloud.translation.v3.IGetGlossaryRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
void

getSupportedLanguages(request, options)

getSupportedLanguages(request?: protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest, options?: CallOptions): Promise<[protos.google.cloud.translation.v3.ISupportedLanguages, (protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest | undefined), {} | undefined]>;

Returns a list of supported languages for translation.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.translation.v3.ISupportedLanguages, (protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest | undefined), {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [SupportedLanguages]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Project or location to make a call. Must refer to a caller's
   *  project.
   *  Format: `projects/{project-number-or-id}` or
   *  `projects/{project-number-or-id}/locations/{location-id}`.
   *  For global calls, use `projects/{project-number-or-id}/locations/global` or
   *  `projects/{project-number-or-id}`.
   *  Non-global location is required for AutoML models.
   *  Only models within the same region (have same location-id) can be used,
   *  otherwise an INVALID_ARGUMENT (400) error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Optional. The language to use to return localized, human readable names
   *  of supported languages. If missing, then display names are not returned
   *  in a response.
   */
  // const displayLanguageCode = 'abc123'
  /**
   *  Optional. Get supported languages of this model.
   *  The format depends on model type:
   *  - AutoML Translation models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
   *  - General (built-in) models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
   *  Returns languages supported by the specified model.
   *  If missing, we get supported languages of Google general NMT model.
   */
  // const model = 'abc123'

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callGetSupportedLanguages() {
    // Construct request
    const request = {
      parent,
    };

    // Run request
    const response = await translationClient.getSupportedLanguages(request);
    console.log(response);
  }

  callGetSupportedLanguages();

getSupportedLanguages(request, options, callback)

getSupportedLanguages(request: protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest, options: CallOptions, callback: Callback<protos.google.cloud.translation.v3.ISupportedLanguages, protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest
options CallOptions
callback Callback<protos.google.cloud.translation.v3.ISupportedLanguages, protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getSupportedLanguages(request, callback)

getSupportedLanguages(request: protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest, callback: Callback<protos.google.cloud.translation.v3.ISupportedLanguages, protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest
callback Callback<protos.google.cloud.translation.v3.ISupportedLanguages, protos.google.cloud.translation.v3.IGetSupportedLanguagesRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

glossaryPath(project, location, glossary)

glossaryPath(project: string, location: string, glossary: string): string;

Return a fully-qualified glossary resource name string.

Parameters
NameDescription
project string
location string
glossary string
Returns
TypeDescription
string

{string} Resource name string.

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
TypeDescription
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

listGlossaries(request, options)

listGlossaries(request?: protos.google.cloud.translation.v3.IListGlossariesRequest, options?: CallOptions): Promise<[protos.google.cloud.translation.v3.IGlossary[], protos.google.cloud.translation.v3.IListGlossariesRequest | null, protos.google.cloud.translation.v3.IListGlossariesResponse]>;

Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't exist.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IListGlossariesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.translation.v3.IGlossary[], protos.google.cloud.translation.v3.IListGlossariesRequest | null, protos.google.cloud.translation.v3.IListGlossariesResponse]>

{Promise} - The promise which resolves to an array. The first element of the array is Array of [Glossary]. The client library will perform auto-pagination by default: it will call the API as many times as needed and will merge results from all the pages into this array. Note that it can affect your quota. We recommend using listGlossariesAsync() method described below for async iteration which you can stop as needed. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) for more details and examples.

listGlossaries(request, options, callback)

listGlossaries(request: protos.google.cloud.translation.v3.IListGlossariesRequest, options: CallOptions, callback: PaginationCallback<protos.google.cloud.translation.v3.IListGlossariesRequest, protos.google.cloud.translation.v3.IListGlossariesResponse | null | undefined, protos.google.cloud.translation.v3.IGlossary>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IListGlossariesRequest
options CallOptions
callback PaginationCallback<protos.google.cloud.translation.v3.IListGlossariesRequest, protos.google.cloud.translation.v3.IListGlossariesResponse | null | undefined, protos.google.cloud.translation.v3.IGlossary>
Returns
TypeDescription
void

listGlossaries(request, callback)

listGlossaries(request: protos.google.cloud.translation.v3.IListGlossariesRequest, callback: PaginationCallback<protos.google.cloud.translation.v3.IListGlossariesRequest, protos.google.cloud.translation.v3.IListGlossariesResponse | null | undefined, protos.google.cloud.translation.v3.IGlossary>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.IListGlossariesRequest
callback PaginationCallback<protos.google.cloud.translation.v3.IListGlossariesRequest, protos.google.cloud.translation.v3.IListGlossariesResponse | null | undefined, protos.google.cloud.translation.v3.IGlossary>
Returns
TypeDescription
void

listGlossariesAsync(request, options)

listGlossariesAsync(request?: protos.google.cloud.translation.v3.IListGlossariesRequest, options?: CallOptions): AsyncIterable<protos.google.cloud.translation.v3.IGlossary>;

Equivalent to listGlossaries, but returns an iterable object.

for-await-of syntax is used with the iterable to get response elements on-demand.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IListGlossariesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
AsyncIterable<protos.google.cloud.translation.v3.IGlossary>

{Object} An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). When you iterate the returned iterable, each element will be an object representing [Glossary]. The API will be called under the hood as needed, once per the page, so you can stop the iteration when you don't need more results. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The name of the project from which to list all of the glossaries.
   */
  // const parent = 'abc123'
  /**
   *  Optional. Requested page size. The server may return fewer glossaries than
   *  requested. If unspecified, the server picks an appropriate default.
   */
  // const pageSize = 1234
  /**
   *  Optional. A token identifying a page of results the server should return.
   *  Typically, this is the value of ListGlossariesResponse.next_page_token
   *  returned from the previous call to `ListGlossaries` method.
   *  The first page is returned if `page_token`is empty or missing.
   */
  // const pageToken = 'abc123'
  /**
   *  Optional. Filter specifying constraints of a list operation.
   *  Specify the constraint by the format of "key=value", where key must be
   *  "src" or "tgt", and the value must be a valid language code.
   *  For multiple restrictions, concatenate them by "AND" (uppercase only),
   *  such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used
   *  here, which means using 'en-US' and 'en' can lead to different results,
   *  which depends on the language code you used when you create the glossary.
   *  For the unidirectional glossaries, the "src" and "tgt" add restrictions
   *  on the source and target language code separately.
   *  For the equivalent term set glossaries, the "src" and/or "tgt" add
   *  restrictions on the term set.
   *  For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional
   *  glossaries which exactly match the source language code as "en-US" and the
   *  target language code "zh-CN", but all equivalent term set glossaries which
   *  contain "en-US" and "zh-CN" in their language set will be picked.
   *  If missing, no filtering is performed.
   */
  // const filter = 'abc123'

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callListGlossaries() {
    // Construct request
    const request = {
      parent,
    };

    // Run request
    const iterable = await translationClient.listGlossariesAsync(request);
    for await (const response of iterable) {
      console.log(response);
    }
  }

  callListGlossaries();

listGlossariesStream(request, options)

listGlossariesStream(request?: protos.google.cloud.translation.v3.IListGlossariesRequest, options?: CallOptions): Transform;

Equivalent to method.name.toCamelCase(), but returns a NodeJS Stream object.

Parameters
NameDescription
request protos.google.cloud.translation.v3.IListGlossariesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Transform

{Stream} An object stream which emits an object representing [Glossary] on 'data' event. The client library will perform auto-pagination by default: it will call the API as many times as needed. Note that it can affect your quota. We recommend using listGlossariesAsync() method described below for async iteration which you can stop as needed. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) for more details and examples.

locationPath(project, location)

locationPath(project: string, location: string): string;

Return a fully-qualified location resource name string.

Parameters
NameDescription
project string
location string
Returns
TypeDescription
string

{string} Resource name string.

matchGlossaryFromGlossaryName(glossaryName)

matchGlossaryFromGlossaryName(glossaryName: string): string | number;

Parse the glossary from Glossary resource.

Parameter
NameDescription
glossaryName string

A fully-qualified path representing Glossary resource.

Returns
TypeDescription
string | number

{string} A string representing the glossary.

matchLocationFromGlossaryName(glossaryName)

matchLocationFromGlossaryName(glossaryName: string): string | number;

Parse the location from Glossary resource.

Parameter
NameDescription
glossaryName string

A fully-qualified path representing Glossary resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromLocationName(locationName)

matchLocationFromLocationName(locationName: string): string | number;

Parse the location from Location resource.

Parameter
NameDescription
locationName string

A fully-qualified path representing Location resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchProjectFromGlossaryName(glossaryName)

matchProjectFromGlossaryName(glossaryName: string): string | number;

Parse the project from Glossary resource.

Parameter
NameDescription
glossaryName string

A fully-qualified path representing Glossary resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromLocationName(locationName)

matchProjectFromLocationName(locationName: string): string | number;

Parse the project from Location resource.

Parameter
NameDescription
locationName string

A fully-qualified path representing Location resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

translateDocument(request, options)

translateDocument(request?: protos.google.cloud.translation.v3.ITranslateDocumentRequest, options?: CallOptions): Promise<[protos.google.cloud.translation.v3.ITranslateDocumentResponse, protos.google.cloud.translation.v3.ITranslateDocumentRequest | undefined, {} | undefined]>;

Translates documents in synchronous mode.

Parameters
NameDescription
request protos.google.cloud.translation.v3.ITranslateDocumentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.translation.v3.ITranslateDocumentResponse, protos.google.cloud.translation.v3.ITranslateDocumentRequest | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [TranslateDocumentResponse]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Location to make a regional call.
   *  Format: `projects/{project-number-or-id}/locations/{location-id}`.
   *  For global calls, use `projects/{project-number-or-id}/locations/global` or
   *  `projects/{project-number-or-id}`.
   *  Non-global location is required for requests using AutoML models or custom
   *  glossaries.
   *  Models and glossaries must be within the same region (have the same
   *  location-id), otherwise an INVALID_ARGUMENT (400) error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Optional. The BCP-47 language code of the input document if known, for
   *  example, "en-US" or "sr-Latn". Supported language codes are listed in
   *  Language Support. If the source language isn't specified, the API attempts
   *  to identify the source language automatically and returns the source
   *  language within the response. Source language must be specified if the
   *  request contains a glossary or a custom model.
   */
  // const sourceLanguageCode = 'abc123'
  /**
   *  Required. The BCP-47 language code to use for translation of the input
   *  document, set to one of the language codes listed in Language Support.
   */
  // const targetLanguageCode = 'abc123'
  /**
   *  Required. Input configurations.
   */
  // const documentInputConfig = {}
  /**
   *  Optional. Output configurations.
   *  Defines if the output file should be stored within Cloud Storage as well
   *  as the desired output format. If not provided the translated file will
   *  only be returned through a byte-stream and its output mime type will be
   *  the same as the input file's mime type.
   */
  // const documentOutputConfig = {}
  /**
   *  Optional. The `model` type requested for this translation.
   *  The format depends on model type:
   *  - AutoML Translation models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
   *  - General (built-in) models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
   *  If not provided, the default Google model (NMT) will be used for
   *  translation.
   */
  // const model = 'abc123'
  /**
   *  Optional. Glossary to be applied. The glossary must be within the same
   *  region (have the same location-id) as the model, otherwise an
   *  INVALID_ARGUMENT (400) error is returned.
   */
  // const glossaryConfig = {}
  /**
   *  Optional. The labels with user-defined metadata for the request.
   *  Label keys and values can be no longer than 63 characters (Unicode
   *  codepoints), can only contain lowercase letters, numeric characters,
   *  underscores and dashes. International characters are allowed. Label values
   *  are optional. Label keys must start with a letter.
   *  See https://cloud.google.com/translate/docs/advanced/labels for more
   *  information.
   */
  // const labels = 1234

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callTranslateDocument() {
    // Construct request
    const request = {
      parent,
      targetLanguageCode,
      documentInputConfig,
    };

    // Run request
    const response = await translationClient.translateDocument(request);
    console.log(response);
  }

  callTranslateDocument();

translateDocument(request, options, callback)

translateDocument(request: protos.google.cloud.translation.v3.ITranslateDocumentRequest, options: CallOptions, callback: Callback<protos.google.cloud.translation.v3.ITranslateDocumentResponse, protos.google.cloud.translation.v3.ITranslateDocumentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.ITranslateDocumentRequest
options CallOptions
callback Callback<protos.google.cloud.translation.v3.ITranslateDocumentResponse, protos.google.cloud.translation.v3.ITranslateDocumentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

translateDocument(request, callback)

translateDocument(request: protos.google.cloud.translation.v3.ITranslateDocumentRequest, callback: Callback<protos.google.cloud.translation.v3.ITranslateDocumentResponse, protos.google.cloud.translation.v3.ITranslateDocumentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.ITranslateDocumentRequest
callback Callback<protos.google.cloud.translation.v3.ITranslateDocumentResponse, protos.google.cloud.translation.v3.ITranslateDocumentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

translateText(request, options)

translateText(request?: protos.google.cloud.translation.v3.ITranslateTextRequest, options?: CallOptions): Promise<[protos.google.cloud.translation.v3.ITranslateTextResponse, protos.google.cloud.translation.v3.ITranslateTextRequest | undefined, {} | undefined]>;

Translates input text and returns translated text.

Parameters
NameDescription
request protos.google.cloud.translation.v3.ITranslateTextRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.translation.v3.ITranslateTextResponse, protos.google.cloud.translation.v3.ITranslateTextRequest | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [TranslateTextResponse]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The content of the input in string format.
   *  We recommend the total content be less than 30k codepoints. The max length
   *  of this field is 1024.
   *  Use BatchTranslateText for larger text.
   */
  // const contents = 'abc123'
  /**
   *  Optional. The format of the source text, for example, "text/html",
   *   "text/plain". If left blank, the MIME type defaults to "text/html".
   */
  // const mimeType = 'abc123'
  /**
   *  Optional. The BCP-47 language code of the input text if
   *  known, for example, "en-US" or "sr-Latn". Supported language codes are
   *  listed in Language Support. If the source language isn't specified, the API
   *  attempts to identify the source language automatically and returns the
   *  source language within the response.
   */
  // const sourceLanguageCode = 'abc123'
  /**
   *  Required. The BCP-47 language code to use for translation of the input
   *  text, set to one of the language codes listed in Language Support.
   */
  // const targetLanguageCode = 'abc123'
  /**
   *  Required. Project or location to make a call. Must refer to a caller's
   *  project.
   *  Format: `projects/{project-number-or-id}` or
   *  `projects/{project-number-or-id}/locations/{location-id}`.
   *  For global calls, use `projects/{project-number-or-id}/locations/global` or
   *  `projects/{project-number-or-id}`.
   *  Non-global location is required for requests using AutoML models or
   *  custom glossaries.
   *  Models and glossaries must be within the same region (have same
   *  location-id), otherwise an INVALID_ARGUMENT (400) error is returned.
   */
  // const parent = 'abc123'
  /**
   *  Optional. The `model` type requested for this translation.
   *  The format depends on model type:
   *  - AutoML Translation models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
   *  - General (built-in) models:
   *    `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
   *  For global (non-regionalized) requests, use `location-id` `global`.
   *  For example,
   *  `projects/{project-number-or-id}/locations/global/models/general/nmt`.
   *  If not provided, the default Google model (NMT) will be used.
   */
  // const model = 'abc123'
  /**
   *  Optional. Glossary to be applied. The glossary must be
   *  within the same region (have the same location-id) as the model, otherwise
   *  an INVALID_ARGUMENT (400) error is returned.
   */
  // const glossaryConfig = {}
  /**
   *  Optional. The labels with user-defined metadata for the request.
   *  Label keys and values can be no longer than 63 characters
   *  (Unicode codepoints), can only contain lowercase letters, numeric
   *  characters, underscores and dashes. International characters are allowed.
   *  Label values are optional. Label keys must start with a letter.
   *  See https://cloud.google.com/translate/docs/advanced/labels for more
   *  information.
   */
  // const labels = 1234

  // Imports the Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3;

  // Instantiates a client
  const translationClient = new TranslationServiceClient();

  async function callTranslateText() {
    // Construct request
    const request = {
      contents,
      targetLanguageCode,
      parent,
    };

    // Run request
    const response = await translationClient.translateText(request);
    console.log(response);
  }

  callTranslateText();

translateText(request, options, callback)

translateText(request: protos.google.cloud.translation.v3.ITranslateTextRequest, options: CallOptions, callback: Callback<protos.google.cloud.translation.v3.ITranslateTextResponse, protos.google.cloud.translation.v3.ITranslateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.ITranslateTextRequest
options CallOptions
callback Callback<protos.google.cloud.translation.v3.ITranslateTextResponse, protos.google.cloud.translation.v3.ITranslateTextRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

translateText(request, callback)

translateText(request: protos.google.cloud.translation.v3.ITranslateTextRequest, callback: Callback<protos.google.cloud.translation.v3.ITranslateTextResponse, protos.google.cloud.translation.v3.ITranslateTextRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.translation.v3.ITranslateTextRequest
callback Callback<protos.google.cloud.translation.v3.ITranslateTextResponse, protos.google.cloud.translation.v3.ITranslateTextRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void