TranslationServiceClient(
transport=None,
channel=None,
credentials=None,
client_config=None,
client_info=None,
client_options=None,
)
Provides natural language translation operations.
Methods
TranslationServiceClient
TranslationServiceClient(
transport=None,
channel=None,
credentials=None,
client_config=None,
client_info=None,
client_options=None,
)
Constructor.
Parameters | |
---|---|
Name | Description |
channel |
grpc.Channel
DEPRECATED. A |
credentials |
google.auth.credentials.Credentials
The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to |
client_config |
dict
DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is 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 |
client_options |
Union[dict, google.api_core.client_options.ClientOptions]
Client options used to set user options on the client. API Endpoint should be set through client_options. |
batch_translate_text
batch_translate_text(source_language_code, target_language_codes, input_configs, output_config, parent=None, models=None, glossaries=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
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.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
TODO: Initialize
source_language_code
:source_language_code = ''
TODO: Initialize
target_language_codes
:target_language_codes = []
TODO: Initialize
input_configs
:input_configs = []
TODO: Initialize
output_config
:output_config = {}
response = client.batch_translate_text(source_language_code, target_language_codes, input_configs, output_config)
def callback(operation_future): ... # Handle result. ... result = operation_future.result()
response.add_done_callback(callback)
Handle metadata.
metadata = response.metadata()
Parameters | |
---|---|
Name | Description |
source_language_code |
str
Required. Source language code. |
target_language_codes |
list[str]
Required. Specify up to 10 language codes here. |
input_configs |
list[Union[dict, InputConfig]]
Required. Input configurations. The total number of files matched should be <= 1000. The total content size should be <= 100M Unicode codepoints. The files must use UTF-8 encoding. If a dict is provided, it must be of the same form as the protobuf message InputConfig |
output_config |
Union[dict, OutputConfig]
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. If a dict is provided, it must be of the same form as the protobuf message OutputConfig |
parent |
str
Required. Location to make a regional call. Format: |
models |
dict[str -> str]
Optional. The models to use for translation. Map's key is target language code. Map's value is model name. Value can be a built-in general model, or an AutoML Translation model. The value format depends on model type: - AutoML Translation models: |
glossaries |
dict[str -> Union[dict, TranslateTextGlossaryConfig]]
Optional. Glossaries to be applied for translation. It's keyed by target language code. If a dict is provided, it must be of the same form as the protobuf message TranslateTextGlossaryConfig |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
create_glossary
create_glossary(parent, glossary, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn't exist.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
parent = client.location_path('[PROJECT]', '[LOCATION]')
TODO: Initialize
glossary
:glossary = {}
response = client.create_glossary(parent, glossary)
def callback(operation_future): ... # Handle result. ... result = operation_future.result()
response.add_done_callback(callback)
Handle metadata.
metadata = response.metadata()
Parameters | |
---|---|
Name | Description |
parent |
str
Required. The project name. |
glossary |
Union[dict, Glossary]
Required. The glossary to create. If a dict is provided, it must be of the same form as the protobuf message Glossary |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
delete_glossary
delete_glossary(name, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet. Returns NOT_FOUND, if the glossary doesn't exist.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
name = client.glossary_path('[PROJECT]', '[LOCATION]', '[GLOSSARY]')
response = client.delete_glossary(name)
def callback(operation_future): ... # Handle result. ... result = operation_future.result()
response.add_done_callback(callback)
Handle metadata.
metadata = response.metadata()
Parameters | |
---|---|
Name | Description |
name |
str
Required. The name of the glossary to delete. |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
detect_language
detect_language(parent=None, model=None, content=None, mime_type=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Detects the language of text within a request.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
response = client.detect_language()
Parameters | |
---|---|
Name | Description |
parent |
str
Required. Location to make a regional or global call. Format: |
model |
str
Optional. The language detection model to be used. Format: |
content |
str
The content of the input stored as a string. |
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". |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
from_service_account_file
from_service_account_file(filename, *args, **kwargs)
Creates an instance of this client using the provided credentials file.
Parameter | |
---|---|
Name | Description |
filename |
str
The path to the service account private key json file. |
Returns | |
---|---|
Type | Description |
TranslationServiceClient | The constructed client. |
from_service_account_json
from_service_account_json(filename, *args, **kwargs)
Creates an instance of this client using the provided credentials file.
Parameter | |
---|---|
Name | Description |
filename |
str
The path to the service account private key json file. |
Returns | |
---|---|
Type | Description |
TranslationServiceClient | The constructed client. |
get_glossary
get_glossary(name, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Gets a glossary. Returns NOT_FOUND, if the glossary doesn't exist.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
name = client.glossary_path('[PROJECT]', '[LOCATION]', '[GLOSSARY]')
response = client.get_glossary(name)
Parameters | |
---|---|
Name | Description |
name |
str
Required. The name of the glossary to retrieve. |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
get_supported_languages
get_supported_languages(parent=None, display_language_code=None, model=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Returns a list of supported languages for translation.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
response = client.get_supported_languages()
Parameters | |
---|---|
Name | Description |
parent |
str
Required. Location to make a regional or global call. Format: |
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. |
model |
str
Optional. Get supported languages of this model. The format depends on model type: - AutoML Translation models: |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
glossary_path
glossary_path(project, location, glossary)
Return a fully-qualified glossary string.
list_glossaries
list_glossaries(parent=None, page_size=None, filter_=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't exist.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
Iterate over all results
for element in client.list_glossaries(): ... # process element ... pass
Alternatively:
Iterate over results one page at a time
for page in client.list_glossaries().pages: ... for element in page: ... # process element ... pass
Parameters | |
---|---|
Name | Description |
parent |
str
Required. The name of the project from which to list all of the glossaries. |
page_size |
int
The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. |
filter_ |
str
Optional. Filter specifying constraints of a list operation. Filtering is not supported yet, and the parameter currently has no effect. If missing, no filtering is performed. |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |
location_path
location_path(project, location)
Return a fully-qualified location string.
translate_text
translate_text(contents, target_language_code, mime_type=None, source_language_code=None, parent=None, model=None, glossary_config=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)
Translates input text and returns translated text.
.. rubric:: Example
from google.cloud import translate_v3beta1
client = translate_v3beta1.TranslationServiceClient()
TODO: Initialize
contents
:contents = []
TODO: Initialize
target_language_code
:target_language_code = ''
response = client.translate_text(contents, target_language_code)
Parameters | |
---|---|
Name | Description |
contents |
list[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. |
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. |
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". |
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. |
parent |
str
Required. Location to make a regional or global call. Format: |
model |
str
Optional. The |
glossary_config |
Union[dict, TranslateTextGlossaryConfig]
Optional. Glossary to be applied. The glossary must be within the same region (have the same location-id) as the model, otherwise an INVALID_ARGUMENT (400) error is returned. If a dict is provided, it must be of the same form as the protobuf message TranslateTextGlossaryConfig |
retry |
Optional[google.api_core.retry.Retry]
A retry object used to retry requests. If |
timeout |
Optional[float]
The amount of time, in seconds, to wait for the request to complete. Note that if |
metadata |
Optional[Sequence[Tuple[str, str]]]
Additional metadata that is provided to the method. |
Exceptions | |
---|---|
Type | Description |
google.api_core.exceptions.GoogleAPICallError | If the request failed for any reason. |
google.api_core.exceptions.RetryError | If the request failed due to a retryable error and retry attempts failed. |
ValueError | If the parameters are invalid. |