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. Repeat this parameter to perform translation operations on multiple text inputs.

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. Can be either base to use the Phrase-Based Machine Translation (PBMT) model, or nmt to use the Neural Machine Translation (NMT) model. If omitted, then nmt is used.

If the model is nmt, and the requested language translation pair is not supported for the NMT model, then the request is translated using the base 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 the following OAuth scope:

  • 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,
  "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. Can be either base for the Phrase-Based Machine Translation (PBMT) model, or nmt for the 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.

Send feedback about...

Translation API