Class TranslationServiceClient (2.19.0)

Provides natural language translation operations.

Equality

Instances of this class created via copy-construction or copy-assignment always compare equal. Instances created with equal std::shared_ptr<*Connection> objects compare equal. Objects that compare equal share the same underlying resources.

Performance

Creating a new instance of this class is a relatively expensive operation, new objects establish new connections to the service. In contrast, copy-construction, move-construction, and the corresponding assignment operations are relatively efficient as the copies share all underlying resources.

Thread Safety

Concurrent access to different instances of this class, even if they compare equal, is guaranteed to work. Two or more threads operating on the same instance of this class is not guaranteed to work. Since copy-construction and move-construction is a relatively efficient operation, consider using such a copy when using this class from multiple threads.

Constructors

TranslationServiceClient(TranslationServiceClient const &)

Copy and move support

Parameter
NameDescription
TranslationServiceClient const &

TranslationServiceClient(TranslationServiceClient &&)

Copy and move support

Parameter
NameDescription
TranslationServiceClient &&

TranslationServiceClient(std::shared_ptr< TranslationServiceConnection >, Options)

Parameters
NameDescription
connection std::shared_ptr< TranslationServiceConnection >
opts Options

Operators

operator=(TranslationServiceClient const &)

Copy and move support

Parameter
NameDescription
TranslationServiceClient const &
Returns
TypeDescription
TranslationServiceClient &

operator=(TranslationServiceClient &&)

Copy and move support

Parameter
NameDescription
TranslationServiceClient &&
Returns
TypeDescription
TranslationServiceClient &

Functions

TranslateText(std::string const &, std::string const &, std::vector< std::string > const &, Options)

Translates input text and returns translated text.

Parameters
NameDescription
parent std::string const &

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.

target_language_code std::string const &

Required. The ISO-639 language code to use for translation of the input text, set to one of the language codes listed in Language Support.

contents std::vector< std::string > const &

Required. The content of the input in string format. We recommend the total content be less than 30,000 codepoints. The max length of this field is 1024. Use BatchTranslateText for larger text.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::TranslateTextResponse >

the result of the RPC. The response message type (google.cloud.translation.v3.TranslateTextResponse) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

TranslateText(std::string const &, std::string const &, std::string const &, std::string const &, std::string const &, std::vector< std::string > const &, Options)

Translates input text and returns translated text.

Parameters
NameDescription
parent std::string const &

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.

model std::string const &

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
mime_type std::string const &

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 std::string const &

Optional. The ISO-639 language code of the input text if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If the source language isn't specified, the API attempts to identify the source language automatically and returns the source language within the response.

target_language_code std::string const &

Required. The ISO-639 language code to use for translation of the input text, set to one of the language codes listed in Language Support.

contents std::vector< std::string > const &

Required. The content of the input in string format. We recommend the total content be less than 30,000 codepoints. The max length of this field is 1024. Use BatchTranslateText for larger text.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::TranslateTextResponse >

the result of the RPC. The response message type (google.cloud.translation.v3.TranslateTextResponse) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

TranslateText(google::cloud::translation::v3::TranslateTextRequest const &, Options)

Translates input text and returns translated text.

Parameters
NameDescription
request google::cloud::translation::v3::TranslateTextRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.TranslateTextRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::TranslateTextResponse >

the result of the RPC. The response message type (google.cloud.translation.v3.TranslateTextResponse) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

DetectLanguage(std::string const &, std::string const &, std::string const &, std::string const &, Options)

Detects the language of text within a request.

Parameters
NameDescription
parent std::string const &

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.

model std::string const &

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.

mime_type std::string const &

Optional. The format of the source text, for example, "text/html", "text/plain". If left blank, the MIME type defaults to "text/html".

content std::string const &

The content of the input stored as a string.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::DetectLanguageResponse >

the result of the RPC. The response message type (google.cloud.translation.v3.DetectLanguageResponse) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

DetectLanguage(google::cloud::translation::v3::DetectLanguageRequest const &, Options)

Detects the language of text within a request.

Parameters
NameDescription
request google::cloud::translation::v3::DetectLanguageRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.DetectLanguageRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::DetectLanguageResponse >

the result of the RPC. The response message type (google.cloud.translation.v3.DetectLanguageResponse) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

GetSupportedLanguages(std::string const &, std::string const &, std::string const &, Options)

Returns a list of supported languages for translation.

Parameters
NameDescription
parent std::string const &

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.

model std::string const &

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.
display_language_code std::string const &

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.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::SupportedLanguages >

the result of the RPC. The response message type (google.cloud.translation.v3.SupportedLanguages) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

GetSupportedLanguages(google::cloud::translation::v3::GetSupportedLanguagesRequest const &, Options)

Returns a list of supported languages for translation.

Parameters
NameDescription
request google::cloud::translation::v3::GetSupportedLanguagesRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.GetSupportedLanguagesRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::SupportedLanguages >

the result of the RPC. The response message type (google.cloud.translation.v3.SupportedLanguages) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

TranslateDocument(google::cloud::translation::v3::TranslateDocumentRequest const &, Options)

Translates documents in synchronous mode.

Parameters
NameDescription
request google::cloud::translation::v3::TranslateDocumentRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.TranslateDocumentRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::TranslateDocumentResponse >

the result of the RPC. The response message type (google.cloud.translation.v3.TranslateDocumentResponse) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

BatchTranslateText(google::cloud::translation::v3::BatchTranslateTextRequest const &, Options)

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
NameDescription
request google::cloud::translation::v3::BatchTranslateTextRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.BatchTranslateTextRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::BatchTranslateResponse > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.BatchTranslateResponse proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.

BatchTranslateDocument(std::string const &, std::string const &, std::vector< std::string > const &, std::vector< google::cloud::translation::v3::BatchDocumentInputConfig > const &, google::cloud::translation::v3::BatchDocumentOutputConfig const &, Options)

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
NameDescription
parent std::string const &

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.

source_language_code std::string const &

Required. The ISO-639 language code of the input document if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support.

target_language_codes std::vector< std::string > const &

Required. The ISO-639 language code to use for translation of the input document. Specify up to 10 language codes here.

input_configs std::vector< google::cloud::translation::v3::BatchDocumentInputConfig > const &

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.

output_config google::cloud::translation::v3::BatchDocumentOutputConfig const &

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.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::BatchTranslateDocumentResponse > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.BatchTranslateDocumentResponse proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.

BatchTranslateDocument(google::cloud::translation::v3::BatchTranslateDocumentRequest const &, Options)

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
NameDescription
request google::cloud::translation::v3::BatchTranslateDocumentRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.BatchTranslateDocumentRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::BatchTranslateDocumentResponse > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.BatchTranslateDocumentResponse proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.

CreateGlossary(std::string const &, google::cloud::translation::v3::Glossary const &, Options)

Creates a glossary and returns the long-running operation.

Returns NOT_FOUND, if the project doesn't exist.

Parameters
NameDescription
parent std::string const &

Required. The project name.

glossary google::cloud::translation::v3::Glossary const &

Required. The glossary to create.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::Glossary > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.Glossary proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.

CreateGlossary(google::cloud::translation::v3::CreateGlossaryRequest const &, Options)

Creates a glossary and returns the long-running operation.

Returns NOT_FOUND, if the project doesn't exist.

Parameters
NameDescription
request google::cloud::translation::v3::CreateGlossaryRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.CreateGlossaryRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::Glossary > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.Glossary proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.

ListGlossaries(std::string const &, Options)

Lists glossaries in a project.

Returns NOT_FOUND, if the project doesn't exist.

Parameters
NameDescription
parent std::string const &

Required. The name of the project from which to list all of the glossaries.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StreamRange< google::cloud::translation::v3::Glossary >

a StreamRange to iterate of the results. See the documentation of this type for details. In brief, this class has begin() and end() member functions returning a iterator class meeting the input iterator requirements. The value type for this iterator is a StatusOr as the iteration may fail even after some values are retrieved successfully, for example, if there is a network disconnect. An empty set of results does not indicate an error, it indicates that there are no resources meeting the request criteria. On a successful iteration the StatusOr<T> contains elements of type google.cloud.translation.v3.Glossary, or rather, the C++ class generated by Protobuf from that type. Please consult the Protobuf documentation for details on the Protobuf mapping rules.

ListGlossaries(google::cloud::translation::v3::ListGlossariesRequest, Options)

Lists glossaries in a project.

Returns NOT_FOUND, if the project doesn't exist.

Parameters
NameDescription
request google::cloud::translation::v3::ListGlossariesRequest

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.ListGlossariesRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StreamRange< google::cloud::translation::v3::Glossary >

a StreamRange to iterate of the results. See the documentation of this type for details. In brief, this class has begin() and end() member functions returning a iterator class meeting the input iterator requirements. The value type for this iterator is a StatusOr as the iteration may fail even after some values are retrieved successfully, for example, if there is a network disconnect. An empty set of results does not indicate an error, it indicates that there are no resources meeting the request criteria. On a successful iteration the StatusOr<T> contains elements of type google.cloud.translation.v3.Glossary, or rather, the C++ class generated by Protobuf from that type. Please consult the Protobuf documentation for details on the Protobuf mapping rules.

GetGlossary(std::string const &, Options)

Gets a glossary.

Returns NOT_FOUND, if the glossary doesn't exist.

Parameters
NameDescription
name std::string const &

Required. The name of the glossary to retrieve.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::Glossary >

the result of the RPC. The response message type (google.cloud.translation.v3.Glossary) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

GetGlossary(google::cloud::translation::v3::GetGlossaryRequest const &, Options)

Gets a glossary.

Returns NOT_FOUND, if the glossary doesn't exist.

Parameters
NameDescription
request google::cloud::translation::v3::GetGlossaryRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.GetGlossaryRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
StatusOr< google::cloud::translation::v3::Glossary >

the result of the RPC. The response message type (google.cloud.translation.v3.Glossary) is mapped to a C++ class using the Protobuf mapping rules. If the request fails, the StatusOr contains the error details.

DeleteGlossary(std::string const &, Options)

Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.

Returns NOT_FOUND, if the glossary doesn't exist.

Parameters
NameDescription
name std::string const &

Required. The name of the glossary to delete.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::DeleteGlossaryResponse > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.DeleteGlossaryResponse proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.

DeleteGlossary(google::cloud::translation::v3::DeleteGlossaryRequest const &, Options)

Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.

Returns NOT_FOUND, if the glossary doesn't exist.

Parameters
NameDescription
request google::cloud::translation::v3::DeleteGlossaryRequest const &

Unary RPCs, such as the one wrapped by this function, receive a single request proto message which includes all the inputs for the RPC. In this case, the proto message is a google.cloud.translation.v3.DeleteGlossaryRequest. Proto messages are converted to C++ classes by Protobuf, using the Protobuf mapping rules.

opts Options

Optional. Override the class-level options, such as retry and backoff policies.

Returns
TypeDescription
future< StatusOr< google::cloud::translation::v3::DeleteGlossaryResponse > >

A future that becomes satisfied when the LRO (Long Running Operation) completes or the polling policy in effect for this call is exhausted. The future is satisfied with an error if the LRO completes with an error or the polling policy is exhausted. In this case the StatusOr returned by the future contains the error. If the LRO completes successfully the value of the future contains the LRO's result. For this RPC the result is a google.cloud.translation.v3.DeleteGlossaryResponse proto message. The C++ class representing this message is created by Protobuf, using the Protobuf mapping rules.