# Translation Client

3.27.0 (latest) 3.25.0 3.24.0 3.23.0 3.22.0 3.21.1 3.20.3 3.19.0 3.18.0 3.17.0 3.15.5 3.14.0 3.13.0 3.12.1 3.11.3 3.10.1 3.9.0 3.8.4 3.7.4 3.6.1 3.5.0 3.4.1 3.3.2 3.2.1 3.1.0 3.0.2 2.0.4 1.7.2 1.6.0 Client for interacting with the Google Cloud Translation API.

### google.cloud.translate_v2.client.BASE(*= 'base* )

Base translation model.

### *class* google.cloud.translate_v2.client.Client(target_language='en', credentials=None, _http=None, client_info=None, client_options=None)

Bases: `google.cloud.client.Client`

Client to bundle configuration needed for API requests.

- **Parameters**

  - **target_language** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- (Optional) The target language used for
    translations and language names. (Defaults to
    `ENGLISH_ISO_639`.)

  - **credentials** ([`Credentials`](https://googleapis.dev/python/google-auth/latest/reference/google.auth.credentials.html#google.auth.credentials.Credentials)) -- (Optional) The OAuth2 Credentials to use for this
    client. If not passed (and if no `_http` object is
    passed), falls back to the default inferred from the
    environment.

  - **_http** (`Session`) -- (Optional) HTTP object to make requests. Can be any object
    that defines `request()` with the same interface as
    `requests.Session.request()`. If not passed, an
    `_http` object is created that is bound to the
    `credentials` for the current object.
    This parameter should be considered private, and could
    change in the future.

  - **client_info** ([`ClientInfo`](https://googleapis.dev/python/google-api-core/latest/client_info.html#google.api_core.client_info.ClientInfo)) -- The client info used to send a user-agent string along with API
    requests. If `None`, then default info will be used. Generally,
    you only need to set this if you're developing your own library
    or partner tool.

  - **client_options** ([`ClientOptions`](https://googleapis.dev/python/google-api-core/latest/client_options.html#google.api_core.client_options.ClientOptions) or [`dict`](https://docs.python.org/3/library/stdtypes.html#dict)) -- (Optional) Client options used to set user options on the client.
    API Endpoint should be set through client_options.

#### SCOPE(*: Union\[Tuple\[[str](https://docs.python.org/3/library/stdtypes.html#str), ...\], [None](https://docs.python.org/3/library/constants.html#None)* *= ('<https://www.googleapis.com/auth/cloud-platform>',* )

The scopes required for authenticating.

#### detect_language(values)

Detect the language of a string or list of strings.

See <https://cloud.google.com/translate/docs/detecting-language>

- **Parameters**

  **values** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)\* or *\[* list\*\](<https://docs.python.org/3/library/stdtypes.html#list>)) -- String or list of strings that will have
  language detected.
- **Return type**

  [dict](https://docs.python.org/3/library/stdtypes.html#dict) or [list](https://docs.python.org/3/library/stdtypes.html#list)
- **Returns**

  A list of dictionaries for each queried value. Each
  dictionary typically contains three keys
  - `confidence`: The confidence in language detection, a
    float between 0 and 1.

  - `input`: The corresponding input value.

  - `language`: The detected language (as an ISO 639-1
    language code).

    though the key `confidence` may not always be present.

    If only a single value is passed, then only a single
    dictionary will be returned.
- **Raises**

  `ValueError` if the number of
  detections is not equal to the number of values.
  `ValueError` if a value
  produces a list of detections with 0 or multiple results
  in it.

#### get_languages(target_language=None)

Get list of supported languages for translation.

Response

See
<https://cloud.google.com/translate/docs/discovering-supported-languages>

- **Parameters**

  **target_language** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- (Optional) The language used to localize
  returned language names. Defaults to the
  target language on the current client.
- **Return type**

  [list](https://docs.python.org/3/library/stdtypes.html#list)
- **Returns**

  List of dictionaries. Each dictionary contains a supported
  ISO 639-1 language code (using the dictionary key
  `language`). If `target_language` is passed, each
  dictionary will also contain the name of each supported
  language (localized to the target language).

#### translate(values, target_language=None, format_=None, source_language=None, customization_ids=(), model=None)

Translate a string or list of strings.

See <https://cloud.google.com/translate/docs/translating-text>

- **Parameters**

  - **values** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)\* or *\[* list\*\](<https://docs.python.org/3/library/stdtypes.html#list>)) -- String or list of strings to translate.

  - **target_language** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The language to translate results into. This
    is required by the API and defaults to
    the target language of the current instance.

  - **format** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- (Optional) One of `text` or `html`, to specify
    if the input text is plain text or HTML.

  - **source_language** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- (Optional) The language of the text to
    be translated.

  - **customization_ids** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)\* or *\[* list\*\](<https://docs.python.org/3/library/stdtypes.html#list>)) -- (Optional) ID or list of customization IDs
    for translation. Sets the `cid` parameter
    in the query.

  - **model** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- (Optional) The model used to translate the text, such
    as `'base'` or `'nmt'`.

- **Return type**

  [dict](https://docs.python.org/3/library/stdtypes.html#dict) or [list](https://docs.python.org/3/library/stdtypes.html#list)
- **Returns**

  A list of dictionaries for each queried value. Each
  dictionary typically contains three keys (though not
  all will be present in all cases)
  - `detectedSourceLanguage`: The detected language (as an
    ISO 639-1 language code) of the text.

  - `translatedText`: The translation of the text into the
    target language.

  - `input`: The corresponding input value.

  - `model`: The model used to translate the text.

    If only a single value is passed, then only a single
    dictionary will be returned.
- **Raises**

  `ValueError` if the number of
  values and translations differ.

### google.cloud.translate_v2.client.ENGLISH_ISO_639(*= 'en* )

ISO 639-1 language code for English.

### google.cloud.translate_v2.client.NMT(*= 'nmt* )

Neural Machine Translation model.