Class TranslationServiceClient (2.46.0)

GitHub RepositoryProduct ReferenceREST DocumentationRPC Documentation

Service Description: Provides natural language translation operations.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   TranslateTextRequest request =
       TranslateTextRequest.newBuilder()
           .addAllContents(new ArrayList<String>())
           .setMimeType("mimeType-1392120434")
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .setTargetLanguageCode("targetLanguageCode-106414698")
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setModel("model104069929")
           .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build())
           .putAllLabels(new HashMap<String, String>())
           .build();
   TranslateTextResponse response = translationServiceClient.translateText(request);
 }
 

Note: close() needs to be called on the TranslationServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

TranslateText

Translates input text and returns translated text.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • translateText(TranslateTextRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • translateTextCallable()

DetectLanguage

Detects the language of text within a request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • detectLanguage(DetectLanguageRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • detectLanguage(LocationName parent, String model, String mimeType)

  • detectLanguage(String parent, String model, String mimeType)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • detectLanguageCallable()

GetSupportedLanguages

Returns a list of supported languages for translation.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getSupportedLanguages(GetSupportedLanguagesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getSupportedLanguages(LocationName parent, String displayLanguageCode, String model)

  • getSupportedLanguages(String parent, String displayLanguageCode, String model)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getSupportedLanguagesCallable()

TranslateDocument

Translates documents in synchronous mode.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • translateDocument(TranslateDocumentRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • translateDocumentCallable()

BatchTranslateText

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • batchTranslateTextAsync(BatchTranslateTextRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • batchTranslateTextOperationCallable()

  • batchTranslateTextCallable()

BatchTranslateDocument

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • batchTranslateDocumentAsync(BatchTranslateDocumentRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • batchTranslateDocumentAsync(LocationName parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)

  • batchTranslateDocumentAsync(String parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • batchTranslateDocumentOperationCallable()

  • batchTranslateDocumentCallable()

CreateGlossary

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

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createGlossaryAsync(CreateGlossaryRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • createGlossaryAsync(LocationName parent, Glossary glossary)

  • createGlossaryAsync(String parent, Glossary glossary)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createGlossaryOperationCallable()

  • createGlossaryCallable()

ListGlossaries

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

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listGlossaries(ListGlossariesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listGlossaries(LocationName parent, String filter)

  • listGlossaries(String parent, String filter)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listGlossariesPagedCallable()

  • listGlossariesCallable()

GetGlossary

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

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getGlossary(GetGlossaryRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getGlossary(GlossaryName name)

  • getGlossary(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getGlossaryCallable()

DeleteGlossary

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

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteGlossaryAsync(DeleteGlossaryRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • deleteGlossaryAsync(GlossaryName name)

  • deleteGlossaryAsync(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteGlossaryOperationCallable()

  • deleteGlossaryCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of TranslationServiceSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TranslationServiceSettings translationServiceSettings =
     TranslationServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 TranslationServiceClient translationServiceClient =
     TranslationServiceClient.create(translationServiceSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TranslationServiceSettings translationServiceSettings =
     TranslationServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 TranslationServiceClient translationServiceClient =
     TranslationServiceClient.create(translationServiceSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TranslationServiceSettings translationServiceSettings =
     TranslationServiceSettings.newHttpJsonBuilder().build();
 TranslationServiceClient translationServiceClient =
     TranslationServiceClient.create(translationServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > TranslationServiceClient

Static Methods

create()

public static final TranslationServiceClient create()

Constructs an instance of TranslationServiceClient with default settings.

Returns
Type Description
TranslationServiceClient
Exceptions
Type Description
IOException

create(TranslationServiceSettings settings)

public static final TranslationServiceClient create(TranslationServiceSettings settings)

Constructs an instance of TranslationServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings TranslationServiceSettings
Returns
Type Description
TranslationServiceClient
Exceptions
Type Description
IOException

create(TranslationServiceStub stub)

public static final TranslationServiceClient create(TranslationServiceStub stub)

Constructs an instance of TranslationServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(TranslationServiceSettings).

Parameter
Name Description
stub TranslationServiceStub
Returns
Type Description
TranslationServiceClient

Constructors

TranslationServiceClient(TranslationServiceSettings settings)

protected TranslationServiceClient(TranslationServiceSettings settings)

Constructs an instance of TranslationServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings TranslationServiceSettings

TranslationServiceClient(TranslationServiceStub stub)

protected TranslationServiceClient(TranslationServiceStub stub)
Parameter
Name Description
stub TranslationServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

batchTranslateDocumentAsync(BatchTranslateDocumentRequest request)

public final OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentAsync(BatchTranslateDocumentRequest request)

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   BatchTranslateDocumentRequest request =
       BatchTranslateDocumentRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .addAllTargetLanguageCodes(new ArrayList<String>())
           .addAllInputConfigs(new ArrayList<BatchDocumentInputConfig>())
           .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build())
           .putAllModels(new HashMap<String, String>())
           .putAllGlossaries(new HashMap<String, TranslateTextGlossaryConfig>())
           .putAllFormatConversions(new HashMap<String, String>())
           .setCustomizedAttribution("customizedAttribution557650238")
           .setEnableShadowRemovalNativePdf(true)
           .setEnableRotationCorrection(true)
           .build();
   BatchTranslateDocumentResponse response =
       translationServiceClient.batchTranslateDocumentAsync(request).get();
 }
 
Parameter
Name Description
request BatchTranslateDocumentRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata>

batchTranslateDocumentAsync(LocationName parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)

public final OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentAsync(LocationName parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   String sourceLanguageCode = "sourceLanguageCode1645917472";
   List<String> targetLanguageCodes = new ArrayList<>();
   List<BatchDocumentInputConfig> inputConfigs = new ArrayList<>();
   BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build();
   BatchTranslateDocumentResponse response =
       translationServiceClient
           .batchTranslateDocumentAsync(
               parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig)
           .get();
 }
 
Parameters
Name Description
parent LocationName

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.

sourceLanguageCode String

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.

targetLanguageCodes List<String>

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

inputConfigs List<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.

outputConfig 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.

Returns
Type Description
OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata>

batchTranslateDocumentAsync(String parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)

public final OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentAsync(String parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   String sourceLanguageCode = "sourceLanguageCode1645917472";
   List<String> targetLanguageCodes = new ArrayList<>();
   List<BatchDocumentInputConfig> inputConfigs = new ArrayList<>();
   BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build();
   BatchTranslateDocumentResponse response =
       translationServiceClient
           .batchTranslateDocumentAsync(
               parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig)
           .get();
 }
 
Parameters
Name Description
parent String

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.

sourceLanguageCode String

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.

targetLanguageCodes List<String>

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

inputConfigs List<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.

outputConfig 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.

Returns
Type Description
OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata>

batchTranslateDocumentCallable()

public final UnaryCallable<BatchTranslateDocumentRequest,Operation> batchTranslateDocumentCallable()

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   BatchTranslateDocumentRequest request =
       BatchTranslateDocumentRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .addAllTargetLanguageCodes(new ArrayList<String>())
           .addAllInputConfigs(new ArrayList<BatchDocumentInputConfig>())
           .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build())
           .putAllModels(new HashMap<String, String>())
           .putAllGlossaries(new HashMap<String, TranslateTextGlossaryConfig>())
           .putAllFormatConversions(new HashMap<String, String>())
           .setCustomizedAttribution("customizedAttribution557650238")
           .setEnableShadowRemovalNativePdf(true)
           .setEnableRotationCorrection(true)
           .build();
   ApiFuture<Operation> future =
       translationServiceClient.batchTranslateDocumentCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
Type Description
UnaryCallable<BatchTranslateDocumentRequest,Operation>

batchTranslateDocumentOperationCallable()

public final OperationCallable<BatchTranslateDocumentRequest,BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentOperationCallable()

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   BatchTranslateDocumentRequest request =
       BatchTranslateDocumentRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .addAllTargetLanguageCodes(new ArrayList<String>())
           .addAllInputConfigs(new ArrayList<BatchDocumentInputConfig>())
           .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build())
           .putAllModels(new HashMap<String, String>())
           .putAllGlossaries(new HashMap<String, TranslateTextGlossaryConfig>())
           .putAllFormatConversions(new HashMap<String, String>())
           .setCustomizedAttribution("customizedAttribution557650238")
           .setEnableShadowRemovalNativePdf(true)
           .setEnableRotationCorrection(true)
           .build();
   OperationFuture<BatchTranslateDocumentResponse, BatchTranslateDocumentMetadata> future =
       translationServiceClient.batchTranslateDocumentOperationCallable().futureCall(request);
   // Do something.
   BatchTranslateDocumentResponse response = future.get();
 }
 
Returns
Type Description
OperationCallable<BatchTranslateDocumentRequest,BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata>

batchTranslateTextAsync(BatchTranslateTextRequest request)

public final OperationFuture<BatchTranslateResponse,BatchTranslateMetadata> batchTranslateTextAsync(BatchTranslateTextRequest request)

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   BatchTranslateTextRequest request =
       BatchTranslateTextRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .addAllTargetLanguageCodes(new ArrayList<String>())
           .putAllModels(new HashMap<String, String>())
           .addAllInputConfigs(new ArrayList<InputConfig>())
           .setOutputConfig(OutputConfig.newBuilder().build())
           .putAllGlossaries(new HashMap<String, TranslateTextGlossaryConfig>())
           .putAllLabels(new HashMap<String, String>())
           .build();
   BatchTranslateResponse response =
       translationServiceClient.batchTranslateTextAsync(request).get();
 }
 
Parameter
Name Description
request BatchTranslateTextRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<BatchTranslateResponse,BatchTranslateMetadata>

batchTranslateTextCallable()

public final UnaryCallable<BatchTranslateTextRequest,Operation> batchTranslateTextCallable()

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   BatchTranslateTextRequest request =
       BatchTranslateTextRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .addAllTargetLanguageCodes(new ArrayList<String>())
           .putAllModels(new HashMap<String, String>())
           .addAllInputConfigs(new ArrayList<InputConfig>())
           .setOutputConfig(OutputConfig.newBuilder().build())
           .putAllGlossaries(new HashMap<String, TranslateTextGlossaryConfig>())
           .putAllLabels(new HashMap<String, String>())
           .build();
   ApiFuture<Operation> future =
       translationServiceClient.batchTranslateTextCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
Type Description
UnaryCallable<BatchTranslateTextRequest,Operation>

batchTranslateTextOperationCallable()

public final OperationCallable<BatchTranslateTextRequest,BatchTranslateResponse,BatchTranslateMetadata> batchTranslateTextOperationCallable()

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.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   BatchTranslateTextRequest request =
       BatchTranslateTextRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .addAllTargetLanguageCodes(new ArrayList<String>())
           .putAllModels(new HashMap<String, String>())
           .addAllInputConfigs(new ArrayList<InputConfig>())
           .setOutputConfig(OutputConfig.newBuilder().build())
           .putAllGlossaries(new HashMap<String, TranslateTextGlossaryConfig>())
           .putAllLabels(new HashMap<String, String>())
           .build();
   OperationFuture<BatchTranslateResponse, BatchTranslateMetadata> future =
       translationServiceClient.batchTranslateTextOperationCallable().futureCall(request);
   // Do something.
   BatchTranslateResponse response = future.get();
 }
 
Returns
Type Description
OperationCallable<BatchTranslateTextRequest,BatchTranslateResponse,BatchTranslateMetadata>

close()

public final void close()

createGlossaryAsync(CreateGlossaryRequest request)

public final OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(CreateGlossaryRequest request)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   CreateGlossaryRequest request =
       CreateGlossaryRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setGlossary(Glossary.newBuilder().build())
           .build();
   Glossary response = translationServiceClient.createGlossaryAsync(request).get();
 }
 
Parameter
Name Description
request CreateGlossaryRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Glossary,CreateGlossaryMetadata>

createGlossaryAsync(LocationName parent, Glossary glossary)

public final OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(LocationName parent, Glossary glossary)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   Glossary glossary = Glossary.newBuilder().build();
   Glossary response = translationServiceClient.createGlossaryAsync(parent, glossary).get();
 }
 
Parameters
Name Description
parent LocationName

Required. The project name.

glossary Glossary

Required. The glossary to create.

Returns
Type Description
OperationFuture<Glossary,CreateGlossaryMetadata>

createGlossaryAsync(String parent, Glossary glossary)

public final OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(String parent, Glossary glossary)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   Glossary glossary = Glossary.newBuilder().build();
   Glossary response = translationServiceClient.createGlossaryAsync(parent, glossary).get();
 }
 
Parameters
Name Description
parent String

Required. The project name.

glossary Glossary

Required. The glossary to create.

Returns
Type Description
OperationFuture<Glossary,CreateGlossaryMetadata>

createGlossaryCallable()

public final UnaryCallable<CreateGlossaryRequest,Operation> createGlossaryCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   CreateGlossaryRequest request =
       CreateGlossaryRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setGlossary(Glossary.newBuilder().build())
           .build();
   ApiFuture<Operation> future =
       translationServiceClient.createGlossaryCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
Type Description
UnaryCallable<CreateGlossaryRequest,Operation>

createGlossaryOperationCallable()

public final OperationCallable<CreateGlossaryRequest,Glossary,CreateGlossaryMetadata> createGlossaryOperationCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   CreateGlossaryRequest request =
       CreateGlossaryRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setGlossary(Glossary.newBuilder().build())
           .build();
   OperationFuture<Glossary, CreateGlossaryMetadata> future =
       translationServiceClient.createGlossaryOperationCallable().futureCall(request);
   // Do something.
   Glossary response = future.get();
 }
 
Returns
Type Description
OperationCallable<CreateGlossaryRequest,Glossary,CreateGlossaryMetadata>

deleteGlossaryAsync(DeleteGlossaryRequest request)

public final OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(DeleteGlossaryRequest request)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   DeleteGlossaryRequest request =
       DeleteGlossaryRequest.newBuilder()
           .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
           .build();
   DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(request).get();
 }
 
Parameter
Name Description
request DeleteGlossaryRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata>

deleteGlossaryAsync(GlossaryName name)

public final OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(GlossaryName name)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
   DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name).get();
 }
 
Parameter
Name Description
name GlossaryName

Required. The name of the glossary to delete.

Returns
Type Description
OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata>

deleteGlossaryAsync(String name)

public final OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(String name)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString();
   DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name).get();
 }
 
Parameter
Name Description
name String

Required. The name of the glossary to delete.

Returns
Type Description
OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata>

deleteGlossaryCallable()

public final UnaryCallable<DeleteGlossaryRequest,Operation> deleteGlossaryCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   DeleteGlossaryRequest request =
       DeleteGlossaryRequest.newBuilder()
           .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
           .build();
   ApiFuture<Operation> future =
       translationServiceClient.deleteGlossaryCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
Type Description
UnaryCallable<DeleteGlossaryRequest,Operation>

deleteGlossaryOperationCallable()

public final OperationCallable<DeleteGlossaryRequest,DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryOperationCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   DeleteGlossaryRequest request =
       DeleteGlossaryRequest.newBuilder()
           .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
           .build();
   OperationFuture<DeleteGlossaryResponse, DeleteGlossaryMetadata> future =
       translationServiceClient.deleteGlossaryOperationCallable().futureCall(request);
   // Do something.
   DeleteGlossaryResponse response = future.get();
 }
 
Returns
Type Description
OperationCallable<DeleteGlossaryRequest,DeleteGlossaryResponse,DeleteGlossaryMetadata>

detectLanguage(DetectLanguageRequest request)

public final DetectLanguageResponse detectLanguage(DetectLanguageRequest request)

Detects the language of text within a request.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   DetectLanguageRequest request =
       DetectLanguageRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setModel("model104069929")
           .setMimeType("mimeType-1392120434")
           .putAllLabels(new HashMap<String, String>())
           .build();
   DetectLanguageResponse response = translationServiceClient.detectLanguage(request);
 }
 
Parameter
Name Description
request DetectLanguageRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
DetectLanguageResponse

detectLanguage(LocationName parent, String model, String mimeType)

public final DetectLanguageResponse detectLanguage(LocationName parent, String model, String mimeType)

Detects the language of text within a request.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   String model = "model104069929";
   String mimeType = "mimeType-1392120434";
   DetectLanguageResponse response =
       translationServiceClient.detectLanguage(parent, model, mimeType);
 }
 
Parameters
Name Description
parent LocationName

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 String

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.

mimeType String

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

Returns
Type Description
DetectLanguageResponse

detectLanguage(String parent, String model, String mimeType)

public final DetectLanguageResponse detectLanguage(String parent, String model, String mimeType)

Detects the language of text within a request.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   String model = "model104069929";
   String mimeType = "mimeType-1392120434";
   DetectLanguageResponse response =
       translationServiceClient.detectLanguage(parent, model, mimeType);
 }
 
Parameters
Name Description
parent String

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 String

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.

mimeType String

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

Returns
Type Description
DetectLanguageResponse

detectLanguageCallable()

public final UnaryCallable<DetectLanguageRequest,DetectLanguageResponse> detectLanguageCallable()

Detects the language of text within a request.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   DetectLanguageRequest request =
       DetectLanguageRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setModel("model104069929")
           .setMimeType("mimeType-1392120434")
           .putAllLabels(new HashMap<String, String>())
           .build();
   ApiFuture<DetectLanguageResponse> future =
       translationServiceClient.detectLanguageCallable().futureCall(request);
   // Do something.
   DetectLanguageResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<DetectLanguageRequest,DetectLanguageResponse>

getGlossary(GetGlossaryRequest request)

public final Glossary getGlossary(GetGlossaryRequest request)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   GetGlossaryRequest request =
       GetGlossaryRequest.newBuilder()
           .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
           .build();
   Glossary response = translationServiceClient.getGlossary(request);
 }
 
Parameter
Name Description
request GetGlossaryRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Glossary

getGlossary(GlossaryName name)

public final Glossary getGlossary(GlossaryName name)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
   Glossary response = translationServiceClient.getGlossary(name);
 }
 
Parameter
Name Description
name GlossaryName

Required. The name of the glossary to retrieve.

Returns
Type Description
Glossary

getGlossary(String name)

public final Glossary getGlossary(String name)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString();
   Glossary response = translationServiceClient.getGlossary(name);
 }
 
Parameter
Name Description
name String

Required. The name of the glossary to retrieve.

Returns
Type Description
Glossary

getGlossaryCallable()

public final UnaryCallable<GetGlossaryRequest,Glossary> getGlossaryCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   GetGlossaryRequest request =
       GetGlossaryRequest.newBuilder()
           .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
           .build();
   ApiFuture<Glossary> future =
       translationServiceClient.getGlossaryCallable().futureCall(request);
   // Do something.
   Glossary response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetGlossaryRequest,Glossary>

getHttpJsonOperationsClient()

public final OperationsClient getHttpJsonOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
Type Description
OperationsClient

getOperationsClient()

public final OperationsClient getOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
Type Description
OperationsClient

getSettings()

public final TranslationServiceSettings getSettings()
Returns
Type Description
TranslationServiceSettings

getStub()

public TranslationServiceStub getStub()
Returns
Type Description
TranslationServiceStub

getSupportedLanguages(GetSupportedLanguagesRequest request)

public final SupportedLanguages getSupportedLanguages(GetSupportedLanguagesRequest request)

Returns a list of supported languages for translation.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   GetSupportedLanguagesRequest request =
       GetSupportedLanguagesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setDisplayLanguageCode("displayLanguageCode-1457478841")
           .setModel("model104069929")
           .build();
   SupportedLanguages response = translationServiceClient.getSupportedLanguages(request);
 }
 
Parameter
Name Description
request GetSupportedLanguagesRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
SupportedLanguages

getSupportedLanguages(LocationName parent, String displayLanguageCode, String model)

public final SupportedLanguages getSupportedLanguages(LocationName parent, String displayLanguageCode, String model)

Returns a list of supported languages for translation.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   String displayLanguageCode = "displayLanguageCode-1457478841";
   String model = "model104069929";
   SupportedLanguages response =
       translationServiceClient.getSupportedLanguages(parent, displayLanguageCode, model);
 }
 
Parameters
Name Description
parent LocationName

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.

displayLanguageCode String

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 String

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.

Returns
Type Description
SupportedLanguages

getSupportedLanguages(String parent, String displayLanguageCode, String model)

public final SupportedLanguages getSupportedLanguages(String parent, String displayLanguageCode, String model)

Returns a list of supported languages for translation.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   String displayLanguageCode = "displayLanguageCode-1457478841";
   String model = "model104069929";
   SupportedLanguages response =
       translationServiceClient.getSupportedLanguages(parent, displayLanguageCode, model);
 }
 
Parameters
Name Description
parent String

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.

displayLanguageCode String

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 String

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.

Returns
Type Description
SupportedLanguages

getSupportedLanguagesCallable()

public final UnaryCallable<GetSupportedLanguagesRequest,SupportedLanguages> getSupportedLanguagesCallable()

Returns a list of supported languages for translation.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   GetSupportedLanguagesRequest request =
       GetSupportedLanguagesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setDisplayLanguageCode("displayLanguageCode-1457478841")
           .setModel("model104069929")
           .build();
   ApiFuture<SupportedLanguages> future =
       translationServiceClient.getSupportedLanguagesCallable().futureCall(request);
   // Do something.
   SupportedLanguages response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetSupportedLanguagesRequest,SupportedLanguages>

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listGlossaries(ListGlossariesRequest request)

public final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(ListGlossariesRequest request)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   ListGlossariesRequest request =
       ListGlossariesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .build();
   for (Glossary element : translationServiceClient.listGlossaries(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListGlossariesRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
TranslationServiceClient.ListGlossariesPagedResponse

listGlossaries(LocationName parent, String filter)

public final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(LocationName parent, String filter)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   String filter = "filter-1274492040";
   for (Glossary element :
       translationServiceClient.listGlossaries(parent, filter).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameters
Name Description
parent LocationName

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

filter String

Optional. Filter specifying constraints of a list operation. Specify the constraint by the format of "key=value", where key must be "src" or "tgt", and the value must be a valid language code. For multiple restrictions, concatenate them by "AND" (uppercase only), such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used here, which means using 'en-US' and 'en' can lead to different results, which depends on the language code you used when you create the glossary. For the unidirectional glossaries, the "src" and "tgt" add restrictions on the source and target language code separately. For the equivalent term set glossaries, the "src" and/or "tgt" add restrictions on the term set. For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional glossaries which exactly match the source language code as "en-US" and the target language code "zh-CN", but all equivalent term set glossaries which contain "en-US" and "zh-CN" in their language set will be picked. If missing, no filtering is performed.

Returns
Type Description
TranslationServiceClient.ListGlossariesPagedResponse

listGlossaries(String parent, String filter)

public final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(String parent, String filter)

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   String filter = "filter-1274492040";
   for (Glossary element :
       translationServiceClient.listGlossaries(parent, filter).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameters
Name Description
parent String

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

filter String

Optional. Filter specifying constraints of a list operation. Specify the constraint by the format of "key=value", where key must be "src" or "tgt", and the value must be a valid language code. For multiple restrictions, concatenate them by "AND" (uppercase only), such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used here, which means using 'en-US' and 'en' can lead to different results, which depends on the language code you used when you create the glossary. For the unidirectional glossaries, the "src" and "tgt" add restrictions on the source and target language code separately. For the equivalent term set glossaries, the "src" and/or "tgt" add restrictions on the term set. For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional glossaries which exactly match the source language code as "en-US" and the target language code "zh-CN", but all equivalent term set glossaries which contain "en-US" and "zh-CN" in their language set will be picked. If missing, no filtering is performed.

Returns
Type Description
TranslationServiceClient.ListGlossariesPagedResponse

listGlossariesCallable()

public final UnaryCallable<ListGlossariesRequest,ListGlossariesResponse> listGlossariesCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   ListGlossariesRequest request =
       ListGlossariesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .build();
   while (true) {
     ListGlossariesResponse response =
         translationServiceClient.listGlossariesCallable().call(request);
     for (Glossary element : response.getGlossariesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListGlossariesRequest,ListGlossariesResponse>

listGlossariesPagedCallable()

public final UnaryCallable<ListGlossariesRequest,TranslationServiceClient.ListGlossariesPagedResponse> listGlossariesPagedCallable()

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

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   ListGlossariesRequest request =
       ListGlossariesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .build();
   ApiFuture<Glossary> future =
       translationServiceClient.listGlossariesPagedCallable().futureCall(request);
   // Do something.
   for (Glossary element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListGlossariesRequest,ListGlossariesPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

translateDocument(TranslateDocumentRequest request)

public final TranslateDocumentResponse translateDocument(TranslateDocumentRequest request)

Translates documents in synchronous mode.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   TranslateDocumentRequest request =
       TranslateDocumentRequest.newBuilder()
           .setParent("parent-995424086")
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .setTargetLanguageCode("targetLanguageCode-106414698")
           .setDocumentInputConfig(DocumentInputConfig.newBuilder().build())
           .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build())
           .setModel("model104069929")
           .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build())
           .putAllLabels(new HashMap<String, String>())
           .setCustomizedAttribution("customizedAttribution557650238")
           .setIsTranslateNativePdfOnly(true)
           .setEnableShadowRemovalNativePdf(true)
           .setEnableRotationCorrection(true)
           .build();
   TranslateDocumentResponse response = translationServiceClient.translateDocument(request);
 }
 
Parameter
Name Description
request TranslateDocumentRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
TranslateDocumentResponse

translateDocumentCallable()

public final UnaryCallable<TranslateDocumentRequest,TranslateDocumentResponse> translateDocumentCallable()

Translates documents in synchronous mode.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   TranslateDocumentRequest request =
       TranslateDocumentRequest.newBuilder()
           .setParent("parent-995424086")
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .setTargetLanguageCode("targetLanguageCode-106414698")
           .setDocumentInputConfig(DocumentInputConfig.newBuilder().build())
           .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build())
           .setModel("model104069929")
           .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build())
           .putAllLabels(new HashMap<String, String>())
           .setCustomizedAttribution("customizedAttribution557650238")
           .setIsTranslateNativePdfOnly(true)
           .setEnableShadowRemovalNativePdf(true)
           .setEnableRotationCorrection(true)
           .build();
   ApiFuture<TranslateDocumentResponse> future =
       translationServiceClient.translateDocumentCallable().futureCall(request);
   // Do something.
   TranslateDocumentResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<TranslateDocumentRequest,TranslateDocumentResponse>

translateText(TranslateTextRequest request)

public final TranslateTextResponse translateText(TranslateTextRequest request)

Translates input text and returns translated text.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   TranslateTextRequest request =
       TranslateTextRequest.newBuilder()
           .addAllContents(new ArrayList<String>())
           .setMimeType("mimeType-1392120434")
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .setTargetLanguageCode("targetLanguageCode-106414698")
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setModel("model104069929")
           .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build())
           .putAllLabels(new HashMap<String, String>())
           .build();
   TranslateTextResponse response = translationServiceClient.translateText(request);
 }
 
Parameter
Name Description
request TranslateTextRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
TranslateTextResponse

translateTextCallable()

public final UnaryCallable<TranslateTextRequest,TranslateTextResponse> translateTextCallable()

Translates input text and returns translated text.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
   TranslateTextRequest request =
       TranslateTextRequest.newBuilder()
           .addAllContents(new ArrayList<String>())
           .setMimeType("mimeType-1392120434")
           .setSourceLanguageCode("sourceLanguageCode1645917472")
           .setTargetLanguageCode("targetLanguageCode-106414698")
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setModel("model104069929")
           .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build())
           .putAllLabels(new HashMap<String, String>())
           .build();
   ApiFuture<TranslateTextResponse> future =
       translationServiceClient.translateTextCallable().futureCall(request);
   // Do something.
   TranslateTextResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<TranslateTextRequest,TranslateTextResponse>