As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

TranslationService

class google.cloud.translate_v3.services.translation_service.TranslationServiceAsyncClient(*, credentials: Optional[google.auth.credentials.Credentials] = None, transport: Union[str, google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport] = 'grpc_asyncio', client_options: Optional[google.api_core.client_options.ClientOptions] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)[source]

Provides natural language translation operations.

Instantiates the translation service client.

Parameters
  • 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 (ClientOptions) – 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.

Raises

google.auth.exceptions.MutualTlsChannelError – If mutual TLS transport creation failed for any reason.

async batch_translate_document(request: Optional[Union[google.cloud.translate_v3.types.translation_service.BatchTranslateDocumentRequest, dict]] = None, *, parent: Optional[str] = None, source_language_code: Optional[str] = None, target_language_codes: Optional[Sequence[str]] = None, input_configs: Optional[Sequence[google.cloud.translate_v3.types.translation_service.BatchDocumentInputConfig]] = None, output_config: Optional[google.cloud.translate_v3.types.translation_service.BatchDocumentOutputConfig] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation_async.AsyncOperation[source]

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.

Parameters
  • 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 BCP-47 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 (Sequence[str]) –

    Required. The BCP-47 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 (Sequence[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

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.BatchTranslateDocumentResponse Stored in the

[google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by BatchTranslateDocument if at least one document is translated successfully.

Return type

google.api_core.operation_async.AsyncOperation

async batch_translate_text(request: Optional[Union[google.cloud.translate_v3.types.translation_service.BatchTranslateTextRequest, dict]] = None, *, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation_async.AsyncOperation[source]

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.

Parameters
Returns

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.BatchTranslateResponse Stored in the

[google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by BatchTranslateText if at least one sentence is translated successfully.

Return type

google.api_core.operation_async.AsyncOperation

static common_billing_account_path(billing_account: str)str

Returns a fully-qualified billing_account string.

static common_folder_path(folder: str)str

Returns a fully-qualified folder string.

static common_location_path(project: str, location: str)str

Returns a fully-qualified location string.

static common_organization_path(organization: str)str

Returns a fully-qualified organization string.

static common_project_path(project: str)str

Returns a fully-qualified project string.

async create_glossary(request: Optional[Union[google.cloud.translate_v3.types.translation_service.CreateGlossaryRequest, dict]] = None, *, parent: Optional[str] = None, glossary: Optional[google.cloud.translate_v3.types.translation_service.Glossary] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation_async.AsyncOperation[source]

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

Parameters
  • 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

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.Glossary Represents a glossary built from user provided data.

Return type

google.api_core.operation_async.AsyncOperation

async delete_glossary(request: Optional[Union[google.cloud.translate_v3.types.translation_service.DeleteGlossaryRequest, dict]] = None, *, name: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation_async.AsyncOperation[source]

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

Parameters
  • 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

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.DeleteGlossaryResponse Stored in the

[google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by DeleteGlossary.

Return type

google.api_core.operation_async.AsyncOperation

async detect_language(request: Optional[Union[google.cloud.translate_v3.types.translation_service.DetectLanguageRequest, dict]] = None, *, parent: Optional[str] = None, model: Optional[str] = None, mime_type: Optional[str] = None, content: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.DetectLanguageResponse[source]

Detects the language of text within a request.

Parameters
  • 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.

Returns

The response message for language detection.

Return type

google.cloud.translate_v3.types.DetectLanguageResponse

classmethod from_service_account_file(filename: str, *args, **kwargs)[source]
Creates an instance of this client using the provided credentials

file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

TranslationServiceAsyncClient

classmethod from_service_account_info(info: dict, *args, **kwargs)[source]
Creates an instance of this client using the provided credentials

info.

Parameters
  • info (dict) – The service account private key info.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

TranslationServiceAsyncClient

classmethod from_service_account_json(filename: str, *args, **kwargs)
Creates an instance of this client using the provided credentials

file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

TranslationServiceAsyncClient

async get_glossary(request: Optional[Union[google.cloud.translate_v3.types.translation_service.GetGlossaryRequest, dict]] = None, *, name: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.Glossary[source]

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

Parameters
  • 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.

Returns

Represents a glossary built from user provided data.

Return type

google.cloud.translate_v3.types.Glossary

async get_supported_languages(request: Optional[Union[google.cloud.translate_v3.types.translation_service.GetSupportedLanguagesRequest, dict]] = None, *, parent: Optional[str] = None, model: Optional[str] = None, display_language_code: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.SupportedLanguages[source]

Returns a list of supported languages for translation.

Parameters
  • 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

The response message for discovering supported languages.

Return type

google.cloud.translate_v3.types.SupportedLanguages

get_transport_class()Type[google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport]

Returns an appropriate transport class.

Parameters

label – The name of the desired transport. If none is provided, then the first transport in the registry is used.

Returns

The transport class to use.

static glossary_path(project: str, location: str, glossary: str)str

Returns a fully-qualified glossary string.

async list_glossaries(request: Optional[Union[google.cloud.translate_v3.types.translation_service.ListGlossariesRequest, dict]] = None, *, parent: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesAsyncPager[source]

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

Parameters
  • 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

Response message for ListGlossaries. Iterating over this object will yield results and resolve additional pages automatically.

Return type

google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesAsyncPager

static parse_common_billing_account_path(path: str)Dict[str, str]

Parse a billing_account path into its component segments.

static parse_common_folder_path(path: str)Dict[str, str]

Parse a folder path into its component segments.

static parse_common_location_path(path: str)Dict[str, str]

Parse a location path into its component segments.

static parse_common_organization_path(path: str)Dict[str, str]

Parse a organization path into its component segments.

static parse_common_project_path(path: str)Dict[str, str]

Parse a project path into its component segments.

static parse_glossary_path(path: str)Dict[str, str]

Parses a glossary path into its component segments.

async translate_document(request: Optional[Union[google.cloud.translate_v3.types.translation_service.TranslateDocumentRequest, dict]] = None, *, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.TranslateDocumentResponse[source]

Translates documents in synchronous mode.

Parameters
Returns

A translated document response message.

Return type

google.cloud.translate_v3.types.TranslateDocumentResponse

async translate_text(request: Optional[Union[google.cloud.translate_v3.types.translation_service.TranslateTextRequest, dict]] = None, *, parent: Optional[str] = None, target_language_code: Optional[str] = None, contents: Optional[Sequence[str]] = None, model: Optional[str] = None, mime_type: Optional[str] = None, source_language_code: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.TranslateTextResponse[source]

Translates input text and returns translated text.

Parameters
  • 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 BCP-47 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 (Sequence[str]) –

    Required. The content of the input in string format. We recommend the total content be less than 30k 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 BCP-47 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.

Returns

Return type

google.cloud.translate_v3.types.TranslateTextResponse

property transport: google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport

Returns the transport used by the client instance.

Returns

The transport used by the client instance.

Return type

TranslationServiceTransport

class google.cloud.translate_v3.services.translation_service.TranslationServiceClient(*, credentials: Optional[google.auth.credentials.Credentials] = None, transport: Optional[Union[str, google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport]] = None, client_options: Optional[google.api_core.client_options.ClientOptions] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)[source]

Provides natural language translation operations.

Instantiates the translation service client.

Parameters
  • 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 (google.api_core.client_options.ClientOptions) – 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.

Raises

google.auth.exceptions.MutualTLSChannelError – If mutual TLS transport creation failed for any reason.

__exit__(type, value, traceback)[source]

Releases underlying transport’s resources.

Warning

ONLY use as a context manager if the transport is NOT shared with other clients! Exiting the with block will CLOSE the transport and may cause errors in other clients!

batch_translate_document(request: Optional[Union[google.cloud.translate_v3.types.translation_service.BatchTranslateDocumentRequest, dict]] = None, *, parent: Optional[str] = None, source_language_code: Optional[str] = None, target_language_codes: Optional[Sequence[str]] = None, input_configs: Optional[Sequence[google.cloud.translate_v3.types.translation_service.BatchDocumentInputConfig]] = None, output_config: Optional[google.cloud.translate_v3.types.translation_service.BatchDocumentOutputConfig] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation.Operation[source]

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.

Parameters
  • 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 BCP-47 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 (Sequence[str]) –

    Required. The BCP-47 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 (Sequence[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

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.BatchTranslateDocumentResponse Stored in the

[google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by BatchTranslateDocument if at least one document is translated successfully.

Return type

google.api_core.operation.Operation

batch_translate_text(request: Optional[Union[google.cloud.translate_v3.types.translation_service.BatchTranslateTextRequest, dict]] = None, *, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation.Operation[source]

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.

Parameters
Returns

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.BatchTranslateResponse Stored in the

[google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by BatchTranslateText if at least one sentence is translated successfully.

Return type

google.api_core.operation.Operation

static common_billing_account_path(billing_account: str)str[source]

Returns a fully-qualified billing_account string.

static common_folder_path(folder: str)str[source]

Returns a fully-qualified folder string.

static common_location_path(project: str, location: str)str[source]

Returns a fully-qualified location string.

static common_organization_path(organization: str)str[source]

Returns a fully-qualified organization string.

static common_project_path(project: str)str[source]

Returns a fully-qualified project string.

create_glossary(request: Optional[Union[google.cloud.translate_v3.types.translation_service.CreateGlossaryRequest, dict]] = None, *, parent: Optional[str] = None, glossary: Optional[google.cloud.translate_v3.types.translation_service.Glossary] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation.Operation[source]

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

Parameters
  • 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

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.Glossary Represents a glossary built from user provided data.

Return type

google.api_core.operation.Operation

delete_glossary(request: Optional[Union[google.cloud.translate_v3.types.translation_service.DeleteGlossaryRequest, dict]] = None, *, name: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.api_core.operation.Operation[source]

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

Parameters
  • 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

An object representing a long-running operation.

The result type for the operation will be google.cloud.translate_v3.types.DeleteGlossaryResponse Stored in the

[google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by DeleteGlossary.

Return type

google.api_core.operation.Operation

detect_language(request: Optional[Union[google.cloud.translate_v3.types.translation_service.DetectLanguageRequest, dict]] = None, *, parent: Optional[str] = None, model: Optional[str] = None, mime_type: Optional[str] = None, content: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.DetectLanguageResponse[source]

Detects the language of text within a request.

Parameters
  • 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.

Returns

The response message for language detection.

Return type

google.cloud.translate_v3.types.DetectLanguageResponse

classmethod from_service_account_file(filename: str, *args, **kwargs)[source]
Creates an instance of this client using the provided credentials

file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

TranslationServiceClient

classmethod from_service_account_info(info: dict, *args, **kwargs)[source]
Creates an instance of this client using the provided credentials

info.

Parameters
  • info (dict) – The service account private key info.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

TranslationServiceClient

classmethod from_service_account_json(filename: str, *args, **kwargs)
Creates an instance of this client using the provided credentials

file.

Parameters
  • filename (str) – The path to the service account private key json file.

  • args – Additional arguments to pass to the constructor.

  • kwargs – Additional arguments to pass to the constructor.

Returns

The constructed client.

Return type

TranslationServiceClient

get_glossary(request: Optional[Union[google.cloud.translate_v3.types.translation_service.GetGlossaryRequest, dict]] = None, *, name: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.Glossary[source]

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

Parameters
  • 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.

Returns

Represents a glossary built from user provided data.

Return type

google.cloud.translate_v3.types.Glossary

get_supported_languages(request: Optional[Union[google.cloud.translate_v3.types.translation_service.GetSupportedLanguagesRequest, dict]] = None, *, parent: Optional[str] = None, model: Optional[str] = None, display_language_code: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.SupportedLanguages[source]

Returns a list of supported languages for translation.

Parameters
  • 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

The response message for discovering supported languages.

Return type

google.cloud.translate_v3.types.SupportedLanguages

static glossary_path(project: str, location: str, glossary: str)str[source]

Returns a fully-qualified glossary string.

list_glossaries(request: Optional[Union[google.cloud.translate_v3.types.translation_service.ListGlossariesRequest, dict]] = None, *, parent: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesPager[source]

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

Parameters
  • 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

Response message for ListGlossaries. Iterating over this object will yield results and resolve additional pages automatically.

Return type

google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesPager

static parse_common_billing_account_path(path: str)Dict[str, str][source]

Parse a billing_account path into its component segments.

static parse_common_folder_path(path: str)Dict[str, str][source]

Parse a folder path into its component segments.

static parse_common_location_path(path: str)Dict[str, str][source]

Parse a location path into its component segments.

static parse_common_organization_path(path: str)Dict[str, str][source]

Parse a organization path into its component segments.

static parse_common_project_path(path: str)Dict[str, str][source]

Parse a project path into its component segments.

static parse_glossary_path(path: str)Dict[str, str][source]

Parses a glossary path into its component segments.

translate_document(request: Optional[Union[google.cloud.translate_v3.types.translation_service.TranslateDocumentRequest, dict]] = None, *, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.TranslateDocumentResponse[source]

Translates documents in synchronous mode.

Parameters
Returns

A translated document response message.

Return type

google.cloud.translate_v3.types.TranslateDocumentResponse

translate_text(request: Optional[Union[google.cloud.translate_v3.types.translation_service.TranslateTextRequest, dict]] = None, *, parent: Optional[str] = None, target_language_code: Optional[str] = None, contents: Optional[Sequence[str]] = None, model: Optional[str] = None, mime_type: Optional[str] = None, source_language_code: Optional[str] = None, retry: Union[google.api_core.retry.Retry, object] = <_MethodDefault._DEFAULT_VALUE: <object object>>, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = ())google.cloud.translate_v3.types.translation_service.TranslateTextResponse[source]

Translates input text and returns translated text.

Parameters
  • 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 BCP-47 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 (Sequence[str]) –

    Required. The content of the input in string format. We recommend the total content be less than 30k 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 BCP-47 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.

Returns

Return type

google.cloud.translate_v3.types.TranslateTextResponse

property transport: google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport

Returns the transport used by the client instance.

Returns

The transport used by the client

instance.

Return type

TranslationServiceTransport

class google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesAsyncPager(method: Callable[[...], Awaitable[google.cloud.translate_v3.types.translation_service.ListGlossariesResponse]], request: google.cloud.translate_v3.types.translation_service.ListGlossariesRequest, response: google.cloud.translate_v3.types.translation_service.ListGlossariesResponse, *, metadata: Sequence[Tuple[str, str]] = ())[source]

A pager for iterating through list_glossaries requests.

This class thinly wraps an initial google.cloud.translate_v3.types.ListGlossariesResponse object, and provides an __aiter__ method to iterate through its glossaries field.

If there are more pages, the __aiter__ method will make additional ListGlossaries requests and continue to iterate through the glossaries field on the corresponding responses.

All the usual google.cloud.translate_v3.types.ListGlossariesResponse attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup.

Instantiates the pager.

Parameters
class google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesPager(method: Callable[[...], google.cloud.translate_v3.types.translation_service.ListGlossariesResponse], request: google.cloud.translate_v3.types.translation_service.ListGlossariesRequest, response: google.cloud.translate_v3.types.translation_service.ListGlossariesResponse, *, metadata: Sequence[Tuple[str, str]] = ())[source]

A pager for iterating through list_glossaries requests.

This class thinly wraps an initial google.cloud.translate_v3.types.ListGlossariesResponse object, and provides an __iter__ method to iterate through its glossaries field.

If there are more pages, the __iter__ method will make additional ListGlossaries requests and continue to iterate through the glossaries field on the corresponding responses.

All the usual google.cloud.translate_v3.types.ListGlossariesResponse attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup.

Instantiate the pager.

Parameters