v2
Source: index.
Child class
Class
Translate
Abstract types
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 |
||||||||||||
|
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 |
||||||||||||
|
|
string |
Yes |
Account email address. Required when using a .pem or .p12 keyFilename. |
||||||||||||
|
credentials |
object |
Yes |
Credentials object. Values in
|
||||||||||||
|
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 |
||||||||||||
|
maxRetries |
number |
Yes |
Maximum number of automatic retries attempted before returning the error. Defaults to |
||||||||||||
|
promise |
Constructor |
Yes |
Custom promise module to use instead of native Promises. |
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
|
||||||||||||
|
apiResponse |
object |
|
The full API response. |
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. |
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
|
||||||||||||
|
apiResponse |
object |
|
The full API response. |
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 |
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. |
TranslateRequest object
Translate request options.
Properties
| Name | Type | Optional | Description |
|---|---|---|---|
|
format |
string |
Yes |
Set the text's format as |
|
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. |