TranslationServiceClient(*, credentials: typing.Optional[google.auth.credentials.Credentials] = None, transport: typing.Optional[typing.Union[str, google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport]] = None, client_options: typing.Optional[typing.Union[google.api_core.client_options.ClientOptions, dict]] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)
Provides natural language translation operations.
Properties
transport
Returns the transport used by the client instance.
Returns | |
---|---|
Type | Description |
TranslationServiceTransport | The transport used by the client instance. |
Methods
TranslationServiceClient
TranslationServiceClient(*, credentials: typing.Optional[google.auth.credentials.Credentials] = None, transport: typing.Optional[typing.Union[str, google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport]] = None, client_options: typing.Optional[typing.Union[google.api_core.client_options.ClientOptions, dict]] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)
Instantiates the translation service client.
Parameters | |
---|---|
Name | Description |
credentials |
Optional[google.auth.credentials.Credentials]
The authorization credentials to attach to requests. These credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. |
transport |
Union[str, TranslationServiceTransport]
The transport to use. If set to None, a transport is chosen automatically. |
client_options |
Optional[Union[google.api_core.client_options.ClientOptions, dict]]
Custom options for the client. It won't take effect if a |
client_info |
google.api_core.gapic_v1.client_info.ClientInfo
The client info used to send a user-agent string along with API requests. If |
Exceptions | |
---|---|
Type | Description |
google.auth.exceptions.MutualTLSChannelError | If mutual TLS transport creation failed for any reason. |
__exit__
__exit__(type, value, traceback)
Releases underlying transport's resources.
detect_language
detect_language(
request: typing.Optional[
typing.Union[
google.cloud.translate_v3.types.translation_service.DetectLanguageRequest,
dict,
]
] = None,
*,
parent: typing.Optional[str] = None,
model: typing.Optional[str] = None,
mime_type: typing.Optional[str] = None,
content: typing.Optional[str] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.cloud.translate_v3.types.translation_service.DetectLanguageResponse
Detects the language of text within a request.
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import translate_v3
def sample_detect_language():
# Create a client
client = translate_v3.TranslationServiceClient()
# Initialize request argument(s)
request = translate_v3.DetectLanguageRequest(
content="content_value",
parent="parent_value",
)
# Make the request
response = client.detect_language(request=request)
# Handle the response
print(response)
Parameters | |
---|---|
Name | Description |
request |
Union[google.cloud.translate_v3.types.DetectLanguageRequest, dict]
The request object. The request message for language detection. |
parent |
str
Required. Project or location to make a call. Must refer to a caller's project. Format: |
model |
str
Optional. The language detection model to be used. Format: |
mime_type |
str
Optional. The format of the source text, for example, "text/html", "text/plain". If left blank, the MIME type defaults to "text/html". This corresponds to the |
content |
str
The content of the input stored as a string. This corresponds to the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Parameter | |
---|---|
Name | Description |
filename |
str
The path to the service account private key json file. |
Returns | |
---|---|
Type | Description |
TranslationServiceClient | The constructed client. |
Exceptions | |
---|---|
Type | Description |
google.auth.exceptions.MutualTLSChannelError | If any errors happen. |
Returns | |
---|---|
Type | Description |
Tuple[str, Callable[[], Tuple[bytes, bytes]]] | returns the API endpoint and the client cert source to use. |
get_supported_languages
get_supported_languages(
request: typing.Optional[
typing.Union[
google.cloud.translate_v3.types.translation_service.GetSupportedLanguagesRequest,
dict,
]
] = None,
*,
parent: typing.Optional[str] = None,
model: typing.Optional[str] = None,
display_language_code: typing.Optional[str] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.cloud.translate_v3.types.translation_service.SupportedLanguages
Returns a list of supported languages for translation.
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import translate_v3
def sample_get_supported_languages():
# Create a client
client = translate_v3.TranslationServiceClient()
# Initialize request argument(s)
request = translate_v3.GetSupportedLanguagesRequest(
parent="parent_value",
)
# Make the request
response = client.get_supported_languages(request=request)
# Handle the response
print(response)
Parameters | |
---|---|
Name | Description |
request |
Union[google.cloud.translate_v3.types.GetSupportedLanguagesRequest, dict]
The request object. The request message for discovering supported languages. |
parent |
str
Required. Project or location to make a call. Must refer to a caller's project. Format: |
model |
str
Optional. Get supported languages of this model. The format depends on model type: - AutoML Translation models: |
display_language_code |
str
Optional. The language to use to return localized, human readable names of supported languages. If missing, then display names are not returned in a response. This corresponds to the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Returns | |
---|---|
Type | Description |
google.cloud.translate_v3.types.SupportedLanguages | The response message for discovering supported languages. |
translate_text
translate_text(
request: typing.Optional[
typing.Union[
google.cloud.translate_v3.types.translation_service.TranslateTextRequest,
dict,
]
] = None,
*,
parent: typing.Optional[str] = None,
target_language_code: typing.Optional[str] = None,
contents: typing.Optional[typing.MutableSequence[str]] = None,
model: typing.Optional[str] = None,
mime_type: typing.Optional[str] = None,
source_language_code: typing.Optional[str] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.cloud.translate_v3.types.translation_service.TranslateTextResponse
Translates input text and returns translated text.
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import translate_v3
def sample_translate_text():
# Create a client
client = translate_v3.TranslationServiceClient()
# Initialize request argument(s)
request = translate_v3.TranslateTextRequest(
contents=['contents_value1', 'contents_value2'],
target_language_code="target_language_code_value",
parent="parent_value",
)
# Make the request
response = client.translate_text(request=request)
# Handle the response
print(response)
Parameters | |
---|---|
Name | Description |
request |
Union[google.cloud.translate_v3.types.TranslateTextRequest, dict]
The request object. The request message for synchronous translation. |
parent |
str
Required. Project or location to make a call. Must refer to a caller's project. Format: |
target_language_code |
str
Required. The ISO-639 language code to use for translation of the input text, set to one of the language codes listed in Language Support. This corresponds to the |
contents |
MutableSequence[str]
Required. The content of the input in string format. We recommend the total content be less than 30,000 codepoints. The max length of this field is 1024. This corresponds to the |
model |
str
Optional. The |
mime_type |
str
Optional. The format of the source text, for example, "text/html", "text/plain". If left blank, the MIME type defaults to "text/html". This corresponds to the |
source_language_code |
str
Optional. The ISO-639 language code of the input text if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If the source language isn't specified, the API attempts to identify the source language automatically and returns the source language within the response. This corresponds to the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |