Client(
target_language="en",
credentials=None,
_http=None,
client_info=None,
client_options=None,
)
Client to bundle configuration needed for API requests.
Parameters |
|
---|---|
Name | Description |
target_language |
str
(Optional) The target language used for translations and language names. (Defaults to :data: |
credentials |
(Optional) The OAuth2 Credentials to use for this client. If not passed (and if no |
_http |
(Optional) HTTP object to make requests. Can be any object that defines |
client_info |
The client info used to send a user-agent string along with API requests. If |
client_options |
(Optional) Client options used to set user options on the client. API Endpoint should be set through client_options. |
Methods
detect_language
detect_language(values)
Detect the language of a string or list of strings.
See https://cloud.google.com/translate/docs/detecting-language
Parameter | |
---|---|
Name | Description |
values |
str or list
String or list of strings that will have language detected. |
Exceptions | |
---|---|
Type | Description |
`ValueErro |
Returns | |
---|---|
Type | Description |
dict or list |
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. |
get_languages
get_languages(target_language=None)
Get list of supported languages for translation.
Response
See https://cloud.google.com/translate/docs/discovering-supported-languages
Parameter | |
---|---|
Name | Description |
target_language |
str
(Optional) The language used to localize returned language names. Defaults to the target language on the current client. |
Returns | |
---|---|
Type | Description |
list |
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
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 | |
---|---|
Name | Description |
values |
str or list
String or list of strings to translate. |
target_language |
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
(Optional) One of |
source_language |
str
(Optional) The language of the text to be translated. |
customization_ids |
str or list
(Optional) ID or list of customization IDs for translation. Sets the |
model |
str
(Optional) The model used to translate the text, such as |
Exceptions | |
---|---|
Type | Description |
`exceptions.ValueError |
if the number of values and translations differ. |
Returns | |
---|---|
Type | Description |
dict or list |
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. |