Child class

Class

Abstract types

static

ClientConfig  object

Properties

Name Type Optional Description

projectId

string

Yes

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

key

string

Yes

An API key. You should prefer using a Service Account key file instead of an API key.

keyFilename

string

Yes

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option above is not necessary. NOTE: .pem and .p12 require you to specify the email option as well.

email

string

Yes

Account email address. Required when using a .pem or .p12 keyFilename.

credentials

object

Yes

Credentials object.

Values in credentials have the following properties:

Name Type Optional Description

client_email

string

Yes

private_key

string

Yes

autoRetry

boolean

Yes

Automatically retry requests if the response is related to rate limits or certain intermittent server errors. We will exponentially backoff subsequent requests by default.

Defaults to true.

maxRetries

number

Yes

Maximum number of automatic retries attempted before returning the error.

Defaults to 3.

promise

Constructor

Yes

Custom promise module to use instead of native Promises.

static

DetectCallback(err, results, apiResponse)

Parameters

Name Type Optional Description

err

Error

 

Request error, if any.

Value can be null.

results

(object or Array of object)

 

The detection results.

Values in results have the following properties:

Name Type Optional Description

language

string

 

The language code matched from the input.

confidence

number

Yes

A float 0 - 1. The higher the number, the higher the confidence in language detection. Note, this is not always returned from the API.

apiResponse

object

 

The full API response.

static

DetectResult  object

Properties

Name Type Optional Description

0.language

string

 

The language code matched from the input.

0.confidence

number

Yes

A float 0 - 1. The higher the number, the higher the confidence in language detection. Note, this is not always returned from the API.

1

object

 

The full API response.

static

GetLanguagesCallback(err, results, apiResponse)

Parameters

Name Type Optional Description

err

Error

 

Request error, if any.

Value can be null.

results

Array of object

 

The languages supported by the API.

Values in results have the following properties:

Name Type Optional Description

code

string

 

The ISO 639-1 language code.

name

string

 

The language name. This can be translated into your preferred language with the target option.

apiResponse

object

 

The full API response.

static

LanguageResult  object

Properties

Name Type Optional Description

code

string

 

The ISO 639-1 language code.

name

string

 

The language name. This can be translated into your preferred language with the target option.

static

TranslateCallback(err, translations, apiResponse)

Parameters

Name Type Optional Description

err

Error

 

Request error, if any.

Value can be null.

translations

(object or Array of object)

 

If a single string input was given, a single translation is given. Otherwise, it is an array of translations.

apiResponse

object

 

The full API response.

static

TranslateRequest  object

Translate request options.

Properties

Name Type Optional Description

format

string

Yes

Set the text's format as html or text. If not provided, we will try to auto-detect if the text given is HTML. If not, we set the format as text.

from

string

Yes

The ISO 639-1 language code the source input is written in.

model

string

Yes

Set the model type requested for this translation. Please refer to the upstream documentation for possible values.

to

string

 

The ISO 639-1 language code to translate the input to.