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.

Services for Google Cloud Translate v3 API

class google.cloud.translate_v3.services.translation_service.TranslationServiceAsyncClient(*, credentials: google.auth.credentials.Credentials = None, transport: Union[str, google.cloud.translate_v3.services.translation_service.transports.base.TranslationServiceTransport] = 'grpc_asyncio', client_options: <module 'google.api_core.client_options' from '/workspace/.nox/docs/lib/python3.8/site-packages/google/api_core/client_options.py'> = 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.

Instantiate 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_text(request: google.cloud.translate_v3.types.translation_service.BatchTranslateTextRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: 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
  • request (BatchTranslateTextRequest) – 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

An object representing a long-running operation.

The result type for the operation will be :class:~.translation_service.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

AsyncOperation

async create_glossary(request: google.cloud.translate_v3.types.translation_service.CreateGlossaryRequest = None, *, parent: str = None, glossary: google.cloud.translate_v3.types.translation_service.Glossary = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (CreateGlossaryRequest) – 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 (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 :class:~.translation_service.Glossary: Represents a glossary built from user provided data.

Return type

AsyncOperation

async delete_glossary(request: google.cloud.translate_v3.types.translation_service.DeleteGlossaryRequest = None, *, name: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (DeleteGlossaryRequest) – 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 :class:~.translation_service.DeleteGlossaryResponse: Stored in the [google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by DeleteGlossary.

Return type

AsyncOperation

async detect_language(request: google.cloud.translate_v3.types.translation_service.DetectLanguageRequest = None, *, parent: str = None, model: str = None, mime_type: str = None, content: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (DetectLanguageRequest) – 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

DetectLanguageResponse

classmethod from_service_account_file(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

{@api.name}

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

{@api.name}

async get_glossary(request: google.cloud.translate_v3.types.translation_service.GetGlossaryRequest = None, *, name: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (GetGlossaryRequest) – 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

Glossary

async get_supported_languages(request: google.cloud.translate_v3.types.translation_service.GetSupportedLanguagesRequest = None, *, parent: str = None, model: str = None, display_language_code: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (GetSupportedLanguagesRequest) – 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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

    Returns languages supported by the specified model. If missing, we get supported languages of Google general base (PBMT) 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

SupportedLanguages

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

Return 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

Return a fully-qualified glossary string.

async list_glossaries(request: google.cloud.translate_v3.types.translation_service.ListGlossariesRequest = None, *, parent: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (ListGlossariesRequest) – 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

ListGlossariesAsyncPager

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

Parse a glossary path into its component segments.

async translate_text(request: google.cloud.translate_v3.types.translation_service.TranslateTextRequest = None, *, parent: str = None, target_language_code: str = None, contents: Sequence[str] = None, model: str = None, mime_type: str = None, source_language_code: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (TranslateTextRequest) – 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. 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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

    For global (non-regionalized) requests, use location-id global. For example, projects/{project-number-or-id}/locations/global/models/general/nmt.

    If missing, the system decides which google base model to use. 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

TranslateTextResponse

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.

Instantiate 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 (client_options_lib.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.

batch_translate_text(request: google.cloud.translate_v3.types.translation_service.BatchTranslateTextRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: 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
  • request (BatchTranslateTextRequest) – 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

An object representing a long-running operation.

The result type for the operation will be :class:~.translation_service.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

Operation

create_glossary(request: google.cloud.translate_v3.types.translation_service.CreateGlossaryRequest = None, *, parent: str = None, glossary: google.cloud.translate_v3.types.translation_service.Glossary = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (CreateGlossaryRequest) – 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 (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 :class:~.translation_service.Glossary: Represents a glossary built from user provided data.

Return type

Operation

delete_glossary(request: google.cloud.translate_v3.types.translation_service.DeleteGlossaryRequest = None, *, name: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (DeleteGlossaryRequest) – 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 :class:~.translation_service.DeleteGlossaryResponse: Stored in the [google.longrunning.Operation.response][google.longrunning.Operation.response] field returned by DeleteGlossary.

Return type

Operation

detect_language(request: google.cloud.translate_v3.types.translation_service.DetectLanguageRequest = None, *, parent: str = None, model: str = None, mime_type: str = None, content: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (DetectLanguageRequest) – 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

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

{@api.name}

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

{@api.name}

get_glossary(request: google.cloud.translate_v3.types.translation_service.GetGlossaryRequest = None, *, name: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (GetGlossaryRequest) – 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

Glossary

get_supported_languages(request: google.cloud.translate_v3.types.translation_service.GetSupportedLanguagesRequest = None, *, parent: str = None, model: str = None, display_language_code: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (GetSupportedLanguagesRequest) – 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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

    Returns languages supported by the specified model. If missing, we get supported languages of Google general base (PBMT) 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

SupportedLanguages

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

Return a fully-qualified glossary string.

list_glossaries(request: google.cloud.translate_v3.types.translation_service.ListGlossariesRequest = None, *, parent: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (ListGlossariesRequest) – 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

ListGlossariesPager

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

Parse a glossary path into its component segments.

translate_text(request: google.cloud.translate_v3.types.translation_service.TranslateTextRequest = None, *, parent: str = None, target_language_code: str = None, contents: Sequence[str] = None, model: str = None, mime_type: str = None, source_language_code: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: 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 (TranslateTextRequest) – 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. 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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

    For global (non-regionalized) requests, use location-id global. For example, projects/{project-number-or-id}/locations/global/models/general/nmt.

    If missing, the system decides which google base model to use. 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

TranslateTextResponse