@Generated(value="by gapic-generator") @BetaApi public class TranslationServiceClient extends Object implements com.google.api.gax.core.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:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String targetLanguageCode = "";
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:
TranslationServiceSettings translationServiceSettings =
TranslationServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TranslationServiceClient translationServiceClient =
TranslationServiceClient.create(translationServiceSettings);
To customize the endpoint:
TranslationServiceSettings translationServiceSettings =
TranslationServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
TranslationServiceClient translationServiceClient =
TranslationServiceClient.create(translationServiceSettings);
| 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) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
com.google.api.gax.longrunning.OperationFuture<BatchTranslateResponse,BatchTranslateMetadata> |
batchTranslateTextAsync(BatchTranslateTextRequest request)
Translates a large volume of text in asynchronous batch mode.
|
com.google.api.gax.rpc.UnaryCallable<BatchTranslateTextRequest,com.google.longrunning.Operation> |
batchTranslateTextCallable()
Translates a large volume of text in asynchronous batch mode.
|
com.google.api.gax.rpc.OperationCallable<BatchTranslateTextRequest,BatchTranslateResponse,BatchTranslateMetadata> |
batchTranslateTextOperationCallable()
Translates a large volume of text in asynchronous batch mode.
|
void |
close() |
static TranslationServiceClient |
create()
Constructs an instance of TranslationServiceClient with default settings.
|
static TranslationServiceClient |
create(TranslationServiceSettings settings)
Constructs an instance of TranslationServiceClient, using the given settings.
|
static TranslationServiceClient |
create(TranslationServiceStub stub)
Constructs an instance of TranslationServiceClient, using the given stub for making calls.
|
com.google.api.gax.longrunning.OperationFuture<Glossary,CreateGlossaryMetadata> |
createGlossaryAsync(CreateGlossaryRequest request)
Creates a glossary and returns the long-running operation.
|
com.google.api.gax.longrunning.OperationFuture<Glossary,CreateGlossaryMetadata> |
createGlossaryAsync(LocationName parent,
Glossary glossary)
Creates a glossary and returns the long-running operation.
|
com.google.api.gax.longrunning.OperationFuture<Glossary,CreateGlossaryMetadata> |
createGlossaryAsync(String parent,
Glossary glossary)
Creates a glossary and returns the long-running operation.
|
com.google.api.gax.rpc.UnaryCallable<CreateGlossaryRequest,com.google.longrunning.Operation> |
createGlossaryCallable()
Creates a glossary and returns the long-running operation.
|
com.google.api.gax.rpc.OperationCallable<CreateGlossaryRequest,Glossary,CreateGlossaryMetadata> |
createGlossaryOperationCallable()
Creates a glossary and returns the long-running operation.
|
com.google.api.gax.longrunning.OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> |
deleteGlossaryAsync(DeleteGlossaryRequest request)
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
com.google.api.gax.longrunning.OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> |
deleteGlossaryAsync(GlossaryName name)
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
com.google.api.gax.longrunning.OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> |
deleteGlossaryAsync(String name)
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
com.google.api.gax.rpc.UnaryCallable<DeleteGlossaryRequest,com.google.longrunning.Operation> |
deleteGlossaryCallable()
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
com.google.api.gax.rpc.OperationCallable<DeleteGlossaryRequest,DeleteGlossaryResponse,DeleteGlossaryMetadata> |
deleteGlossaryOperationCallable()
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
DetectLanguageResponse |
detectLanguage(DetectLanguageRequest request)
Detects the language of text within a request.
|
DetectLanguageResponse |
detectLanguage(LocationName parent,
String model,
String mimeType,
String content)
Detects the language of text within a request.
|
DetectLanguageResponse |
detectLanguage(String parent,
String model,
String mimeType,
String content)
Detects the language of text within a request.
|
com.google.api.gax.rpc.UnaryCallable<DetectLanguageRequest,DetectLanguageResponse> |
detectLanguageCallable()
Detects the language of text within a request.
|
Glossary |
getGlossary(GetGlossaryRequest request)
Gets a glossary.
|
Glossary |
getGlossary(GlossaryName name)
Gets a glossary.
|
Glossary |
getGlossary(String name)
Gets a glossary.
|
com.google.api.gax.rpc.UnaryCallable<GetGlossaryRequest,Glossary> |
getGlossaryCallable()
Gets a glossary.
|
com.google.longrunning.OperationsClient |
getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
TranslationServiceSettings |
getSettings() |
TranslationServiceStub |
getStub() |
SupportedLanguages |
getSupportedLanguages(GetSupportedLanguagesRequest request)
Returns a list of supported languages for translation.
|
SupportedLanguages |
getSupportedLanguages(LocationName parent,
String model,
String displayLanguageCode)
Returns a list of supported languages for translation.
|
SupportedLanguages |
getSupportedLanguages(String parent,
String model,
String displayLanguageCode)
Returns a list of supported languages for translation.
|
com.google.api.gax.rpc.UnaryCallable<GetSupportedLanguagesRequest,SupportedLanguages> |
getSupportedLanguagesCallable()
Returns a list of supported languages for translation.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
TranslationServiceClient.ListGlossariesPagedResponse |
listGlossaries(ListGlossariesRequest request)
Lists glossaries in a project.
|
TranslationServiceClient.ListGlossariesPagedResponse |
listGlossaries(LocationName parent)
Lists glossaries in a project.
|
TranslationServiceClient.ListGlossariesPagedResponse |
listGlossaries(String parent)
Lists glossaries in a project.
|
com.google.api.gax.rpc.UnaryCallable<ListGlossariesRequest,ListGlossariesResponse> |
listGlossariesCallable()
Lists glossaries in a project.
|
com.google.api.gax.rpc.UnaryCallable<ListGlossariesRequest,TranslationServiceClient.ListGlossariesPagedResponse> |
listGlossariesPagedCallable()
Lists glossaries in a project.
|
void |
shutdown() |
void |
shutdownNow() |
TranslateTextResponse |
translateText(LocationName parent,
String targetLanguageCode,
List<String> contents)
Translates input text and returns translated text.
|
TranslateTextResponse |
translateText(LocationName parent,
String model,
String mimeType,
String sourceLanguageCode,
String targetLanguageCode,
List<String> contents)
Translates input text and returns translated text.
|
TranslateTextResponse |
translateText(String parent,
String targetLanguageCode,
List<String> contents)
Translates input text and returns translated text.
|
TranslateTextResponse |
translateText(String parent,
String model,
String mimeType,
String sourceLanguageCode,
String targetLanguageCode,
List<String> contents)
Translates input text and returns translated text.
|
TranslateTextResponse |
translateText(TranslateTextRequest request)
Translates input text and returns translated text.
|
com.google.api.gax.rpc.UnaryCallable<TranslateTextRequest,TranslateTextResponse> |
translateTextCallable()
Translates input text and returns translated text.
|
protected TranslationServiceClient(TranslationServiceSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected TranslationServiceClient(TranslationServiceStub stub)
public static final TranslationServiceClient create() throws IOException
IOExceptionpublic static final TranslationServiceClient create(TranslationServiceSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final TranslationServiceClient create(TranslationServiceStub stub)
public final TranslationServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public TranslationServiceStub getStub()
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.longrunning.OperationsClient getOperationsClient()
public final TranslateTextResponse translateText(LocationName parent, String targetLanguageCode, List<String> contents)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String targetLanguageCode = "";
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. Use BatchTranslateText for larger text.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TranslateTextResponse translateText(String parent, String targetLanguageCode, List<String> contents)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String targetLanguageCode = "";
List<String> contents = new ArrayList<>();
TranslateTextResponse response = translationServiceClient.translateText(parent.toString(), 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. Use BatchTranslateText for larger text.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TranslateTextResponse translateText(LocationName parent, String model, String mimeType, String sourceLanguageCode, String targetLanguageCode, List<String> contents)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String model = "";
String mimeType = "";
String sourceLanguageCode = "";
String targetLanguageCode = "";
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`, `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
For global (non-regionalized) requests, use `location-id` `global`. For example, `projects/{project-number-or-id}/locations/global/models/general/nmt`.
If missing, the system decides which google base model to use.
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. Use BatchTranslateText for larger text.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TranslateTextResponse translateText(String parent, String model, String mimeType, String sourceLanguageCode, String targetLanguageCode, List<String> contents)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String model = "";
String mimeType = "";
String sourceLanguageCode = "";
String targetLanguageCode = "";
List<String> contents = new ArrayList<>();
TranslateTextResponse response = translationServiceClient.translateText(parent.toString(), 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`, `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
For global (non-regionalized) requests, use `location-id` `global`. For example, `projects/{project-number-or-id}/locations/global/models/general/nmt`.
If missing, the system decides which google base model to use.
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. Use BatchTranslateText for larger text.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TranslateTextResponse translateText(TranslateTextRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
List<String> contents = new ArrayList<>();
String targetLanguageCode = "";
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
TranslateTextRequest request = TranslateTextRequest.newBuilder()
.addAllContents(contents)
.setTargetLanguageCode(targetLanguageCode)
.setParent(parent.toString())
.build();
TranslateTextResponse response = translationServiceClient.translateText(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<TranslateTextRequest,TranslateTextResponse> translateTextCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
List<String> contents = new ArrayList<>();
String targetLanguageCode = "";
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
TranslateTextRequest request = TranslateTextRequest.newBuilder()
.addAllContents(contents)
.setTargetLanguageCode(targetLanguageCode)
.setParent(parent.toString())
.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:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String model = "";
String mimeType = "";
String content = "";
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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final DetectLanguageResponse detectLanguage(String parent, String model, String mimeType, String content)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String model = "";
String mimeType = "";
String content = "";
DetectLanguageResponse response = translationServiceClient.detectLanguage(parent.toString(), 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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final DetectLanguageResponse detectLanguage(DetectLanguageRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
DetectLanguageRequest request = DetectLanguageRequest.newBuilder()
.setParent(parent.toString())
.build();
DetectLanguageResponse response = translationServiceClient.detectLanguage(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DetectLanguageRequest,DetectLanguageResponse> detectLanguageCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
DetectLanguageRequest request = DetectLanguageRequest.newBuilder()
.setParent(parent.toString())
.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:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String model = "";
String displayLanguageCode = "";
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`, `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
Returns languages supported by the specified model. If missing, we get supported languages of Google general base (PBMT) model.
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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final SupportedLanguages getSupportedLanguages(String parent, String model, String displayLanguageCode)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String model = "";
String displayLanguageCode = "";
SupportedLanguages response = translationServiceClient.getSupportedLanguages(parent.toString(), 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`, `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
Returns languages supported by the specified model. If missing, we get supported languages of Google general base (PBMT) model.
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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final SupportedLanguages getSupportedLanguages(GetSupportedLanguagesRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
GetSupportedLanguagesRequest request = GetSupportedLanguagesRequest.newBuilder()
.setParent(parent.toString())
.build();
SupportedLanguages response = translationServiceClient.getSupportedLanguages(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetSupportedLanguagesRequest,SupportedLanguages> getSupportedLanguagesCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
GetSupportedLanguagesRequest request = GetSupportedLanguagesRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<SupportedLanguages> future = translationServiceClient.getSupportedLanguagesCallable().futureCall(request);
// Do something
SupportedLanguages response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.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:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String sourceLanguageCode = "";
List<String> targetLanguageCodes = new ArrayList<>();
List<InputConfig> inputConfigs = new ArrayList<>();
OutputConfig outputConfig = OutputConfig.newBuilder().build();
BatchTranslateTextRequest request = BatchTranslateTextRequest.newBuilder()
.setParent(parent.toString())
.setSourceLanguageCode(sourceLanguageCode)
.addAllTargetLanguageCodes(targetLanguageCodes)
.addAllInputConfigs(inputConfigs)
.setOutputConfig(outputConfig)
.build();
BatchTranslateResponse response = translationServiceClient.batchTranslateTextAsync(request).get();
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final com.google.api.gax.rpc.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:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String sourceLanguageCode = "";
List<String> targetLanguageCodes = new ArrayList<>();
List<InputConfig> inputConfigs = new ArrayList<>();
OutputConfig outputConfig = OutputConfig.newBuilder().build();
BatchTranslateTextRequest request = BatchTranslateTextRequest.newBuilder()
.setParent(parent.toString())
.setSourceLanguageCode(sourceLanguageCode)
.addAllTargetLanguageCodes(targetLanguageCodes)
.addAllInputConfigs(inputConfigs)
.setOutputConfig(outputConfig)
.build();
OperationFuture<BatchTranslateResponse, BatchTranslateMetadata> future = translationServiceClient.batchTranslateTextOperationCallable().futureCall(request);
// Do something
BatchTranslateResponse response = future.get();
}
public final com.google.api.gax.rpc.UnaryCallable<BatchTranslateTextRequest,com.google.longrunning.Operation> batchTranslateTextCallable()
This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String sourceLanguageCode = "";
List<String> targetLanguageCodes = new ArrayList<>();
List<InputConfig> inputConfigs = new ArrayList<>();
OutputConfig outputConfig = OutputConfig.newBuilder().build();
BatchTranslateTextRequest request = BatchTranslateTextRequest.newBuilder()
.setParent(parent.toString())
.setSourceLanguageCode(sourceLanguageCode)
.addAllTargetLanguageCodes(targetLanguageCodes)
.addAllInputConfigs(inputConfigs)
.setOutputConfig(outputConfig)
.build();
ApiFuture<Operation> future = translationServiceClient.batchTranslateTextCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(LocationName parent, Glossary glossary)
Sample code:
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.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(String parent, Glossary glossary)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
Glossary response = translationServiceClient.createGlossaryAsync(parent.toString(), glossary).get();
}
parent - Required. The project name.glossary - Required. The glossary to create.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<Glossary,CreateGlossaryMetadata> createGlossaryAsync(CreateGlossaryRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder()
.setParent(parent.toString())
.setGlossary(glossary)
.build();
Glossary response = translationServiceClient.createGlossaryAsync(request).get();
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final com.google.api.gax.rpc.OperationCallable<CreateGlossaryRequest,Glossary,CreateGlossaryMetadata> createGlossaryOperationCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder()
.setParent(parent.toString())
.setGlossary(glossary)
.build();
OperationFuture<Glossary, CreateGlossaryMetadata> future = translationServiceClient.createGlossaryOperationCallable().futureCall(request);
// Do something
Glossary response = future.get();
}
public final com.google.api.gax.rpc.UnaryCallable<CreateGlossaryRequest,com.google.longrunning.Operation> createGlossaryCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder()
.setParent(parent.toString())
.setGlossary(glossary)
.build();
ApiFuture<Operation> future = translationServiceClient.createGlossaryCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(LocationName parent)
Sample code:
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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(String parent)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
for (Glossary element : translationServiceClient.listGlossaries(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The name of the project from which to list all of the glossaries.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(ListGlossariesRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListGlossariesRequest request = ListGlossariesRequest.newBuilder()
.setParent(parent.toString())
.build();
for (Glossary element : translationServiceClient.listGlossaries(request).iterateAll()) {
// doThingsWith(element);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListGlossariesRequest,TranslationServiceClient.ListGlossariesPagedResponse> listGlossariesPagedCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListGlossariesRequest request = ListGlossariesRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListGlossariesPagedResponse> future = translationServiceClient.listGlossariesPagedCallable().futureCall(request);
// Do something
for (Glossary element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListGlossariesRequest,ListGlossariesResponse> listGlossariesCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListGlossariesRequest request = ListGlossariesRequest.newBuilder()
.setParent(parent.toString())
.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:
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.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Glossary getGlossary(String name)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
Glossary response = translationServiceClient.getGlossary(name.toString());
}
name - Required. The name of the glossary to retrieve.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Glossary getGlossary(GetGlossaryRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
GetGlossaryRequest request = GetGlossaryRequest.newBuilder()
.setName(name.toString())
.build();
Glossary response = translationServiceClient.getGlossary(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetGlossaryRequest,Glossary> getGlossaryCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
GetGlossaryRequest request = GetGlossaryRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Glossary> future = translationServiceClient.getGlossaryCallable().futureCall(request);
// Do something
Glossary response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(GlossaryName name)
Sample code:
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.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(String name)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name.toString()).get();
}
name - Required. The name of the glossary to delete.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryAsync(DeleteGlossaryRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder()
.setName(name.toString())
.build();
DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(request).get();
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final com.google.api.gax.rpc.OperationCallable<DeleteGlossaryRequest,DeleteGlossaryResponse,DeleteGlossaryMetadata> deleteGlossaryOperationCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder()
.setName(name.toString())
.build();
OperationFuture<DeleteGlossaryResponse, DeleteGlossaryMetadata> future = translationServiceClient.deleteGlossaryOperationCallable().futureCall(request);
// Do something
DeleteGlossaryResponse response = future.get();
}
public final com.google.api.gax.rpc.UnaryCallable<DeleteGlossaryRequest,com.google.longrunning.Operation> deleteGlossaryCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Operation> future = translationServiceClient.deleteGlossaryCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2019 Google LLC. All rights reserved.