@Generated(value="by gapic-generator-java") public class TranslationServiceClient extends Object implements BackgroundResource
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()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String targetLanguageCode = "targetLanguageCode-106414698";
List<String> contents = new ArrayList<>();
TranslateTextResponse response =
translationServiceClient.translateText(parent, targetLanguageCode, contents);
}
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().
The surface of this class includes several types of Java methods for each of the API's methods:
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.newBuilder()
.setTransportChannelProvider(
TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
.build();
TranslationServiceClient translationServiceClient =
TranslationServiceClient.create(translationServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier and Type | Class and Description |
---|---|
static class |
TranslationServiceClient.ListGlossariesFixedSizeCollection |
static class |
TranslationServiceClient.ListGlossariesPage |
static class |
TranslationServiceClient.ListGlossariesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
TranslationServiceClient(TranslationServiceSettings settings)
Constructs an instance of TranslationServiceClient, using the given settings.
|
protected |
TranslationServiceClient(TranslationServiceStub stub) |
protected TranslationServiceClient(TranslationServiceSettings settings) throws IOException
IOException
protected TranslationServiceClient(TranslationServiceStub stub)
public static final TranslationServiceClient create() throws IOException
IOException
public static final TranslationServiceClient create(TranslationServiceSettings settings) throws IOException
IOException
public static final TranslationServiceClient create(TranslationServiceStub stub)
public final TranslationServiceSettings getSettings()
public TranslationServiceStub getStub()
public final OperationsClient getOperationsClient()
@BetaApi public final OperationsClient getHttpJsonOperationsClient()
public final TranslateTextResponse translateText(LocationName parent, String targetLanguageCode, List<String> contents)
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 targetLanguageCode = "targetLanguageCode-106414698";
List<String> contents = new ArrayList<>();
TranslateTextResponse response =
translationServiceClient.translateText(parent, targetLanguageCode, contents);
}
parent
- 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.
targetLanguageCode
- Required. The BCP-47 language code to use for translation of the
input text, set to one of the language codes listed in Language Support.contents
- Required. The content of the input in string format. We recommend the total
content be less than 30k codepoints. The max length of this field is 1024. Use
BatchTranslateText for larger text.ApiException
- if the remote call failspublic final TranslateTextResponse translateText(String parent, String targetLanguageCode, List<String> contents)
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 targetLanguageCode = "targetLanguageCode-106414698";
List<String> contents = new ArrayList<>();
TranslateTextResponse response =
translationServiceClient.translateText(parent, targetLanguageCode, contents);
}
parent
- 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.
targetLanguageCode
- Required. The BCP-47 language code to use for translation of the
input text, set to one of the language codes listed in Language Support.contents
- Required. The content of the input in string format. We recommend the total
content be less than 30k codepoints. The max length of this field is 1024. Use
BatchTranslateText for larger text.ApiException
- if the remote call failspublic final TranslateTextResponse translateText(LocationName parent, String model, String mimeType, String sourceLanguageCode, String targetLanguageCode, List<String> contents)
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";
String sourceLanguageCode = "sourceLanguageCode1645917472";
String targetLanguageCode = "targetLanguageCode-106414698";
List<String> contents = new ArrayList<>();
TranslateTextResponse response =
translationServiceClient.translateText(
parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents);
}
parent
- 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
- 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.
mimeType
- Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type defaults to "text/html".sourceLanguageCode
- Optional. The BCP-47 language code of the input text if known, for
example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If
the source language isn't specified, the API attempts to identify the source language
automatically and returns the source language within the response.targetLanguageCode
- Required. The BCP-47 language code to use for translation of the
input text, set to one of the language codes listed in Language Support.contents
- Required. The content of the input in string format. We recommend the total
content be less than 30k codepoints. The max length of this field is 1024. Use
BatchTranslateText for larger text.ApiException
- if the remote call failspublic final TranslateTextResponse translateText(String parent, String model, String mimeType, String sourceLanguageCode, String targetLanguageCode, List<String> contents)
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";
String sourceLanguageCode = "sourceLanguageCode1645917472";
String targetLanguageCode = "targetLanguageCode-106414698";
List<String> contents = new ArrayList<>();
TranslateTextResponse response =
translationServiceClient.translateText(
parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents);
}
parent
- 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
- 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.
mimeType
- Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type defaults to "text/html".sourceLanguageCode
- Optional. The BCP-47 language code of the input text if known, for
example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If
the source language isn't specified, the API attempts to identify the source language
automatically and returns the source language within the response.targetLanguageCode
- Required. The BCP-47 language code to use for translation of the
input text, set to one of the language codes listed in Language Support.contents
- Required. The content of the input in string format. We recommend the total
content be less than 30k codepoints. The max length of this field is 1024. Use
BatchTranslateText for larger text.ApiException
- if the remote call failspublic final TranslateTextResponse translateText(TranslateTextRequest 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()) {
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);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<TranslateTextRequest,TranslateTextResponse> translateTextCallable()
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();
}
public final DetectLanguageResponse detectLanguage(LocationName parent, String model, String mimeType, String content)
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";
String content = "content951530617";
DetectLanguageResponse response =
translationServiceClient.detectLanguage(parent, model, mimeType, content);
}
parent
- 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
- 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
- Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type defaults to "text/html".content
- The content of the input stored as a string.ApiException
- if the remote call failspublic final DetectLanguageResponse detectLanguage(String parent, String model, String mimeType, String content)
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";
String content = "content951530617";
DetectLanguageResponse response =
translationServiceClient.detectLanguage(parent, model, mimeType, content);
}
parent
- 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
- 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
- Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type defaults to "text/html".content
- The content of the input stored as a string.ApiException
- if the remote call failspublic final DetectLanguageResponse detectLanguage(DetectLanguageRequest 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);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<DetectLanguageRequest,DetectLanguageResponse> detectLanguageCallable()
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();
}
public final SupportedLanguages getSupportedLanguages(LocationName parent, String model, String displayLanguageCode)
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 displayLanguageCode = "displayLanguageCode-1457478841";
SupportedLanguages response =
translationServiceClient.getSupportedLanguages(parent, model, displayLanguageCode);
}
parent
- 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
- 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.
displayLanguageCode
- 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.ApiException
- if the remote call failspublic final SupportedLanguages getSupportedLanguages(String parent, String model, String displayLanguageCode)
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 displayLanguageCode = "displayLanguageCode-1457478841";
SupportedLanguages response =
translationServiceClient.getSupportedLanguages(parent, model, displayLanguageCode);
}
parent
- 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
- 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.
displayLanguageCode
- 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.ApiException
- if the remote call failspublic final SupportedLanguages getSupportedLanguages(GetSupportedLanguagesRequest 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()) {
GetSupportedLanguagesRequest request =
GetSupportedLanguagesRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setDisplayLanguageCode("displayLanguageCode-1457478841")
.setModel("model104069929")
.build();
SupportedLanguages response = translationServiceClient.getSupportedLanguages(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetSupportedLanguagesRequest,SupportedLanguages> getSupportedLanguagesCallable()
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();
}
public final TranslateDocumentResponse translateDocument(TranslateDocumentRequest 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()) {
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>())
.build();
TranslateDocumentResponse response = translationServiceClient.translateDocument(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<TranslateDocumentRequest,TranslateDocumentResponse> translateDocumentCallable()
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>())
.build();
ApiFuture<TranslateDocumentResponse> future =
translationServiceClient.translateDocumentCallable().futureCall(request);
// Do something.
TranslateDocumentResponse response = future.get();
}
public final OperationFuture<BatchTranslateResponse,BatchTranslateMetadata> batchTranslateTextAsync(BatchTranslateTextRequest request)
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();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<BatchTranslateTextRequest,BatchTranslateResponse,BatchTranslateMetadata> batchTranslateTextOperationCallable()
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();
}
public final UnaryCallable<BatchTranslateTextRequest,Operation> batchTranslateTextCallable()
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();
}
public final OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentAsync(LocationName parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)
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();
}
parent
- 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
- Required. The BCP-47 language code of the input document if known,
for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support
(https://cloud.google.com/translate/docs/languages).targetLanguageCodes
- Required. The BCP-47 language code to use for translation of the
input document. Specify up to 10 language codes here.inputConfigs
- 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
- 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.ApiException
- if the remote call failspublic final OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentAsync(String parent, String sourceLanguageCode, List<String> targetLanguageCodes, List<BatchDocumentInputConfig> inputConfigs, BatchDocumentOutputConfig outputConfig)
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();
}
parent
- 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
- Required. The BCP-47 language code of the input document if known,
for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support
(https://cloud.google.com/translate/docs/languages).targetLanguageCodes
- Required. The BCP-47 language code to use for translation of the
input document. Specify up to 10 language codes here.inputConfigs
- 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
- 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.ApiException
- if the remote call failspublic final OperationFuture<BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentAsync(BatchTranslateDocumentRequest request)
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>())
.build();
BatchTranslateDocumentResponse response =
translationServiceClient.batchTranslateDocumentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<BatchTranslateDocumentRequest,BatchTranslateDocumentResponse,BatchTranslateDocumentMetadata> batchTranslateDocumentOperationCallable()
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>())
.build();
OperationFuture<BatchTranslateDocumentResponse, BatchTranslateDocumentMetadata> future =
translationServiceClient.batchTranslateDocumentOperationCallable().futureCall(request);
// Do something.
BatchTranslateDocumentResponse response = future.get();
}
public final UnaryCallable<BatchTranslateDocumentRequest,Operation> batchTranslateDocumentCallable()
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>())
.build();
ApiFuture<Operation> future =
translationServiceClient.batchTranslateDocumentCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(LocationName parent, Glossary glossary)
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();
}
parent
- Required. The project name.glossary
- Required. The glossary to create.ApiException
- if the remote call failspublic final OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(String parent, Glossary glossary)
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();
}
parent
- Required. The project name.glossary
- Required. The glossary to create.ApiException
- if the remote call failspublic final OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(CreateGlossaryRequest 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()) {
CreateGlossaryRequest request =
CreateGlossaryRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
.setGlossary(Glossary.newBuilder().build())
.build();
Glossary response = translationServiceClient.createGlossaryAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<CreateGlossaryRequest,Glossary,CreateGlossaryMetadata> createGlossaryOperationCallable()
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();
}
public final UnaryCallable<CreateGlossaryRequest,Operation> createGlossaryCallable()
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();
}
public final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(LocationName parent)
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]");
for (Glossary element : translationServiceClient.listGlossaries(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The name of the project from which to list all of the glossaries.ApiException
- if the remote call failspublic final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(String parent)
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();
for (Glossary element : translationServiceClient.listGlossaries(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The name of the project from which to list all of the glossaries.ApiException
- if the remote call failspublic final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(ListGlossariesRequest 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()) {
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);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<ListGlossariesRequest,TranslationServiceClient.ListGlossariesPagedResponse> listGlossariesPagedCallable()
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);
}
}
public final UnaryCallable<ListGlossariesRequest,ListGlossariesResponse> listGlossariesCallable()
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;
}
}
}
public final Glossary getGlossary(GlossaryName name)
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);
}
name
- Required. The name of the glossary to retrieve.ApiException
- if the remote call failspublic final Glossary getGlossary(String name)
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);
}
name
- Required. The name of the glossary to retrieve.ApiException
- if the remote call failspublic final Glossary getGlossary(GetGlossaryRequest 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()) {
GetGlossaryRequest request =
GetGlossaryRequest.newBuilder()
.setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
.build();
Glossary response = translationServiceClient.getGlossary(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetGlossaryRequest,Glossary> getGlossaryCallable()
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();
}
public final OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(GlossaryName name)
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();
}
name
- Required. The name of the glossary to delete.ApiException
- if the remote call failspublic final OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(String name)
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();
}
name
- Required. The name of the glossary to delete.ApiException
- if the remote call failspublic final OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(DeleteGlossaryRequest 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()) {
DeleteGlossaryRequest request =
DeleteGlossaryRequest.newBuilder()
.setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString())
.build();
DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<DeleteGlossaryRequest,DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryOperationCallable()
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();
}
public final UnaryCallable<DeleteGlossaryRequest,Operation> deleteGlossaryCallable()
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();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2022 Google LLC. All rights reserved.