Method: translate

Translates input text, returning translated text.

HTTP request

POST https://translation.googleapis.com/language/translate/v2

The URL uses Google API HTTP annotation syntax.

Query parameters

Parameters
q

string

Required The input text to translate. Provide an array of strings to translate multiple phrases. The maximum number of strings is 128.

target

string

Required The language to use for translation of the input text, set to one of the language codes listed in Language Support.

format

string

The format of the source text, in either HTML (default) or plain-text. A value of html indicates HTML and a value of text indicates plain-text.

source

string

The language of the source text, set to one of the language codes listed in Language Support. If the source language is not specified, the API will attempt to detect the source language automatically and return it within the response.

model

string

The translation model. Cloud Translation - Basic offers only the nmt Neural Machine Translation (NMT) model.

If the model is base, the request is translated by using the NMT model.

key

string

A valid API key to handle requests for this API. If you are using OAuth 2.0 service account credentials (recommended), do not supply this parameter.

Response body

If successful, the response body contains data with the following structure:

JSON representation
{
  "data": {
    object(TranslateTextResponseList)
  },
}
Fields
data

object(TranslateTextResponseList)

The list of language translation responses. This list contains a language translation response for each query (q) sent in the language translation request.

Authorization

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/cloud-translation
  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Auth Guide.

TranslateTextResponseList

A response list contains a list of separate language translation responses.

JSON representation
{
  "translations": [
    array
  ],
}
Fields
translations[]

array (TranslateTextResponseTranslation)

Contains list of translation results of the supplied text.

TranslateTextResponseTranslation

Contains a list of translation results for the requested text.

JSON representation
{
  "detectedSourceLanguage": string,
  "model": string,
  "translatedText": string,
}
Fields
detectedSourceLanguage

string

The source language of the initial request, detected automatically, if no source language was passed within the initial request. If the source language was passed, auto-detection of the language will not occur and this field will be omitted.

model

string

The translation model. Cloud Translation - Basic offers only the nmt Neural Machine Translation (NMT) model.

If you did not include a model parameter with your request, then this field is not included in the response.

translatedText

string

Text translated into the target language.