Class TranslationServiceClient (3.12.0)

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
TypeDescription
TranslationServiceTransportThe 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
NameDescription
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 transport instance is provided. (1) The api_endpoint property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always use the default regular endpoint) and "auto" (auto switch to the default mTLS endpoint if client certificate is present, this is the default value). However, the api_endpoint property takes precedence if provided. (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is "true", then the client_cert_source property can be used to provide client certificate for mutual TLS transport. If not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used.

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 None, then default info will be used. Generally, you only need to set this if you're developing your own client library.

Exceptions
TypeDescription
google.auth.exceptions.MutualTLSChannelErrorIf mutual TLS transport creation failed for any reason.

__exit__

__exit__(type, value, traceback)

Releases underlying transport's resources.

batch_translate_document

batch_translate_document(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.BatchTranslateDocumentRequest,
            dict,
        ]
    ] = None,
    *,
    parent: typing.Optional[str] = None,
    source_language_code: typing.Optional[str] = None,
    target_language_codes: typing.Optional[typing.MutableSequence[str]] = None,
    input_configs: typing.Optional[
        typing.MutableSequence[
            google.cloud.translate_v3.types.translation_service.BatchDocumentInputConfig
        ]
    ] = None,
    output_config: typing.Optional[
        google.cloud.translate_v3.types.translation_service.BatchDocumentOutputConfig
    ] = 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.api_core.operation.Operation

Translates a large volume of document in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location. This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.

# 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_batch_translate_document():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    input_configs = translate_v3.BatchDocumentInputConfig()
    input_configs.gcs_source.input_uri = "input_uri_value"

    output_config = translate_v3.BatchDocumentOutputConfig()
    output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value"

    request = translate_v3.BatchTranslateDocumentRequest(
        parent="parent_value",
        source_language_code="source_language_code_value",
        target_language_codes=['target_language_codes_value1', 'target_language_codes_value2'],
        input_configs=input_configs,
        output_config=output_config,
    )

    # Make the request
    operation = client.batch_translate_document(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.BatchTranslateDocumentRequest, dict]

The request object. The BatchTranslateDocument request.

parent str

Required. Location to make a regional call. Format: projects/{project-number-or-id}/locations/{location-id}. The global location is not supported for batch translation. Only AutoML Translation models or glossaries within the same region (have the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned. This corresponds to the parent field on the request instance; if request is provided, this should not be set.

source_language_code str

Required. The ISO-639 language code of the input document if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support https://cloud.google.com/translate/docs/languages__. This corresponds to the source_language_code field on the request instance; if request is provided, this should not be set.

target_language_codes MutableSequence[str]

Required. The ISO-639 language code to use for translation of the input document. Specify up to 10 language codes here. This corresponds to the target_language_codes field on the request instance; if request is provided, this should not be set.

input_configs MutableSequence[google.cloud.translate_v3.types.BatchDocumentInputConfig]

Required. Input configurations. The total number of files matched should be <= 100. The total content size to translate should be <= 100M Unicode codepoints. The files must use UTF-8 encoding. This corresponds to the input_configs field on the request instance; if request is provided, this should not be set.

output_config google.cloud.translate_v3.types.BatchDocumentOutputConfig

Required. Output configuration. If 2 input configs match to the same file (that is, same input path), we don't generate output for duplicate inputs. This corresponds to the output_config field on the request instance; if request is provided, this should not be set.

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
TypeDescription
google.api_core.operation.OperationAn object representing a long-running operation. The result type for the operation will be BatchTranslateDocumentResponse Stored in the google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by BatchTranslateDocument if at least one document is translated successfully.

batch_translate_text

batch_translate_text(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.BatchTranslateTextRequest,
            dict,
        ]
    ] = 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.api_core.operation.Operation

Translates a large volume of text in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location. This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.

# 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_batch_translate_text():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    input_configs = translate_v3.InputConfig()
    input_configs.gcs_source.input_uri = "input_uri_value"

    output_config = translate_v3.OutputConfig()
    output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value"

    request = translate_v3.BatchTranslateTextRequest(
        parent="parent_value",
        source_language_code="source_language_code_value",
        target_language_codes=['target_language_codes_value1', 'target_language_codes_value2'],
        input_configs=input_configs,
        output_config=output_config,
    )

    # Make the request
    operation = client.batch_translate_text(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.BatchTranslateTextRequest, dict]

The request object. The batch translation request.

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
TypeDescription
google.api_core.operation.OperationAn object representing a long-running operation. The result type for the operation will be BatchTranslateResponse Stored in the google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by BatchTranslateText if at least one sentence is translated successfully.

create_glossary

create_glossary(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.CreateGlossaryRequest,
            dict,
        ]
    ] = None,
    *,
    parent: typing.Optional[str] = None,
    glossary: typing.Optional[
        google.cloud.translate_v3.types.translation_service.Glossary
    ] = 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.api_core.operation.Operation

Creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn't exist.

# 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_create_glossary():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    glossary = translate_v3.Glossary()
    glossary.name = "name_value"

    request = translate_v3.CreateGlossaryRequest(
        parent="parent_value",
        glossary=glossary,
    )

    # Make the request
    operation = client.create_glossary(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.CreateGlossaryRequest, dict]

The request object. Request message for CreateGlossary.

parent str

Required. The project name. This corresponds to the parent field on the request instance; if request is provided, this should not be set.

glossary google.cloud.translate_v3.types.Glossary

Required. The glossary to create. This corresponds to the glossary field on the request instance; if request is provided, this should not be set.

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
TypeDescription
google.api_core.operation.OperationAn object representing a long-running operation. The result type for the operation will be Glossary Represents a glossary built from user-provided data.

delete_glossary

delete_glossary(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.DeleteGlossaryRequest,
            dict,
        ]
    ] = None,
    *,
    name: 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.api_core.operation.Operation

Deletes a glossary, or cancels glossary construction if the glossary isn't created yet. Returns NOT_FOUND, if the glossary doesn't exist.

# 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_delete_glossary():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    request = translate_v3.DeleteGlossaryRequest(
        name="name_value",
    )

    # Make the request
    operation = client.delete_glossary(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.DeleteGlossaryRequest, dict]

The request object. Request message for DeleteGlossary.

name str

Required. The name of the glossary to delete. This corresponds to the name field on the request instance; if request is provided, this should not be set.

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
TypeDescription
google.api_core.operation.OperationAn object representing a long-running operation. The result type for the operation will be DeleteGlossaryResponse Stored in the google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by DeleteGlossary.

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
NameDescription
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: projects/{project-number-or-id}/locations/{location-id} or projects/{project-number-or-id}. For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}. Only models within the same region (has same location-id) can be used. Otherwise an INVALID_ARGUMENT (400) error is returned. This corresponds to the parent field on the request instance; if request is provided, this should not be set.

model str

Optional. The language detection model to be used. Format: projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id} Only one language detection model is currently supported: projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default. If not specified, the default model is used. This corresponds to the model field on the request instance; if request is provided, this should not be set.

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 mime_type field on the request instance; if request is provided, this should not be set.

content str

The content of the input stored as a string. This corresponds to the content field on the request instance; if request is provided, this should not be set.

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
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
TranslationServiceClientThe constructed client.

get_glossary

get_glossary(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.GetGlossaryRequest, dict
        ]
    ] = None,
    *,
    name: 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.Glossary

Gets a glossary. Returns NOT_FOUND, if the glossary doesn't exist.

# 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_glossary():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    request = translate_v3.GetGlossaryRequest(
        name="name_value",
    )

    # Make the request
    response = client.get_glossary(request=request)

    # Handle the response
    print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.GetGlossaryRequest, dict]

The request object. Request message for GetGlossary.

name str

Required. The name of the glossary to retrieve. This corresponds to the name field on the request instance; if request is provided, this should not be set.

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.

Exceptions
TypeDescription
google.auth.exceptions.MutualTLSChannelErrorIf any errors happen.
Returns
TypeDescription
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
NameDescription
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: projects/{project-number-or-id} or projects/{project-number-or-id}/locations/{location-id}. For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}. Non-global location is required for AutoML models. Only models within the same region (have same location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned. This corresponds to the parent field on the request instance; if request is provided, this should not be set.

model str

Optional. Get supported languages of this model. The format depends on model type: - AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id} - General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt, Returns languages supported by the specified model. If missing, we get supported languages of Google general NMT model. This corresponds to the model field on the request instance; if request is provided, this should not be set.

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 display_language_code field on the request instance; if request is provided, this should not be set.

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
TypeDescription
google.cloud.translate_v3.types.SupportedLanguagesThe response message for discovering supported languages.

glossary_path

glossary_path(project: str, location: str, glossary: str) -> str

Returns a fully-qualified glossary string.

list_glossaries

list_glossaries(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.ListGlossariesRequest,
            dict,
        ]
    ] = None,
    *,
    parent: 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.services.translation_service.pagers.ListGlossariesPager

Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't exist.

# 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_list_glossaries():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    request = translate_v3.ListGlossariesRequest(
        parent="parent_value",
    )

    # Make the request
    page_result = client.list_glossaries(request=request)

    # Handle the response
    for response in page_result:
        print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.ListGlossariesRequest, dict]

The request object. Request message for ListGlossaries.

parent str

Required. The name of the project from which to list all of the glossaries. This corresponds to the parent field on the request instance; if request is provided, this should not be set.

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
TypeDescription
google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesPagerResponse message for ListGlossaries. Iterating over this object will yield results and resolve additional pages automatically.

parse_glossary_path

parse_glossary_path(path: str) -> typing.Dict[str, str]

Parses a glossary path into its component segments.

translate_document

translate_document(
    request: typing.Optional[
        typing.Union[
            google.cloud.translate_v3.types.translation_service.TranslateDocumentRequest,
            dict,
        ]
    ] = 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.TranslateDocumentResponse

Translates documents in synchronous mode.

# 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_document():
    # Create a client
    client = translate_v3.TranslationServiceClient()

    # Initialize request argument(s)
    document_input_config = translate_v3.DocumentInputConfig()
    document_input_config.content = b'content_blob'

    request = translate_v3.TranslateDocumentRequest(
        parent="parent_value",
        target_language_code="target_language_code_value",
        document_input_config=document_input_config,
    )

    # Make the request
    response = client.translate_document(request=request)

    # Handle the response
    print(response)
Parameters
NameDescription
request Union[google.cloud.translate_v3.types.TranslateDocumentRequest, dict]

The request object. A document translation request.

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
TypeDescription
google.cloud.translate_v3.types.TranslateDocumentResponseA translated document response message.

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
NameDescription
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: projects/{project-number-or-id} or projects/{project-number-or-id}/locations/{location-id}. For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}. Non-global location is required for requests using AutoML models or custom glossaries. Models and glossaries must be within the same region (have same location-id), otherwise an INVALID_ARGUMENT (400) error is returned. This corresponds to the parent field on the request instance; if request is provided, this should not be set.

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 target_language_code field on the request instance; if request is provided, this should not be set.

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. Use BatchTranslateText for larger text. This corresponds to the contents field on the request instance; if request is provided, this should not be set.

model str

Optional. The model type requested for this translation. The format depends on model type: - AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id} - General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt, For global (non-regionalized) requests, use location-id global. For example, projects/{project-number-or-id}/locations/global/models/general/nmt. If not provided, the default Google model (NMT) will be used This corresponds to the model field on the request instance; if request is provided, this should not be set.

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 mime_type field on the request instance; if request is provided, this should not be set.

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 source_language_code field on the request instance; if request is provided, this should not be set.

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.