@Generated(value="by gapic-generator") @BetaApi 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:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
String model = "";
String mimeType = "";
DetectLanguageResponse response = translationServiceClient.detectLanguage(formattedParent, model, mimeType);
}
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) |
OperationFuture<com.google.cloud.translate.v3beta1.BatchTranslateResponse,com.google.cloud.translate.v3beta1.BatchTranslateMetadata> |
batchTranslateTextAsync(com.google.cloud.translate.v3beta1.BatchTranslateTextRequest request)
Translates a large volume of text in asynchronous batch mode.
|
UnaryCallable<com.google.cloud.translate.v3beta1.BatchTranslateTextRequest,Operation> |
batchTranslateTextCallable()
Translates a large volume of text in asynchronous batch mode.
|
OperationCallable<com.google.cloud.translate.v3beta1.BatchTranslateTextRequest,com.google.cloud.translate.v3beta1.BatchTranslateResponse,com.google.cloud.translate.v3beta1.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.
|
OperationFuture<com.google.cloud.translate.v3beta1.Glossary,com.google.cloud.translate.v3beta1.CreateGlossaryMetadata> |
createGlossaryAsync(com.google.cloud.translate.v3beta1.CreateGlossaryRequest request)
Creates a glossary and returns the long-running operation.
|
OperationFuture<com.google.cloud.translate.v3beta1.Glossary,com.google.cloud.translate.v3beta1.CreateGlossaryMetadata> |
createGlossaryAsync(String parent,
com.google.cloud.translate.v3beta1.Glossary glossary)
Creates a glossary and returns the long-running operation.
|
UnaryCallable<com.google.cloud.translate.v3beta1.CreateGlossaryRequest,Operation> |
createGlossaryCallable()
Creates a glossary and returns the long-running operation.
|
OperationCallable<com.google.cloud.translate.v3beta1.CreateGlossaryRequest,com.google.cloud.translate.v3beta1.Glossary,com.google.cloud.translate.v3beta1.CreateGlossaryMetadata> |
createGlossaryOperationCallable()
Creates a glossary and returns the long-running operation.
|
OperationFuture<com.google.cloud.translate.v3beta1.DeleteGlossaryResponse,com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata> |
deleteGlossaryAsync(com.google.cloud.translate.v3beta1.DeleteGlossaryRequest request)
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
OperationFuture<com.google.cloud.translate.v3beta1.DeleteGlossaryResponse,com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata> |
deleteGlossaryAsync(String name)
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
UnaryCallable<com.google.cloud.translate.v3beta1.DeleteGlossaryRequest,Operation> |
deleteGlossaryCallable()
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
OperationCallable<com.google.cloud.translate.v3beta1.DeleteGlossaryRequest,com.google.cloud.translate.v3beta1.DeleteGlossaryResponse,com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata> |
deleteGlossaryOperationCallable()
Deletes a glossary, or cancels glossary construction if the glossary isn't created yet.
|
com.google.cloud.translate.v3beta1.DetectLanguageResponse |
detectLanguage(com.google.cloud.translate.v3beta1.DetectLanguageRequest request)
Detects the language of text within a request.
|
com.google.cloud.translate.v3beta1.DetectLanguageResponse |
detectLanguage(String parent,
String model,
String mimeType)
Detects the language of text within a request.
|
UnaryCallable<com.google.cloud.translate.v3beta1.DetectLanguageRequest,com.google.cloud.translate.v3beta1.DetectLanguageResponse> |
detectLanguageCallable()
Detects the language of text within a request.
|
static String |
formatGlossaryName(String project,
String location,
String glossary)
Deprecated.
Use the
GlossaryName class instead. |
static String |
formatLocationName(String project,
String location)
Deprecated.
Use the
LocationName class instead. |
com.google.cloud.translate.v3beta1.Glossary |
getGlossary(com.google.cloud.translate.v3beta1.GetGlossaryRequest request)
Gets a glossary.
|
com.google.cloud.translate.v3beta1.Glossary |
getGlossary(String name)
Gets a glossary.
|
UnaryCallable<com.google.cloud.translate.v3beta1.GetGlossaryRequest,com.google.cloud.translate.v3beta1.Glossary> |
getGlossaryCallable()
Gets a glossary.
|
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() |
com.google.cloud.translate.v3beta1.SupportedLanguages |
getSupportedLanguages(com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest request)
Returns a list of supported languages for translation.
|
com.google.cloud.translate.v3beta1.SupportedLanguages |
getSupportedLanguages(String parent,
String displayLanguageCode,
String model)
Returns a list of supported languages for translation.
|
UnaryCallable<com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest,com.google.cloud.translate.v3beta1.SupportedLanguages> |
getSupportedLanguagesCallable()
Returns a list of supported languages for translation.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
TranslationServiceClient.ListGlossariesPagedResponse |
listGlossaries(com.google.cloud.translate.v3beta1.ListGlossariesRequest request)
Lists glossaries in a project.
|
TranslationServiceClient.ListGlossariesPagedResponse |
listGlossaries(String parent,
String filter)
Lists glossaries in a project.
|
UnaryCallable<com.google.cloud.translate.v3beta1.ListGlossariesRequest,com.google.cloud.translate.v3beta1.ListGlossariesResponse> |
listGlossariesCallable()
Lists glossaries in a project.
|
UnaryCallable<com.google.cloud.translate.v3beta1.ListGlossariesRequest,TranslationServiceClient.ListGlossariesPagedResponse> |
listGlossariesPagedCallable()
Lists glossaries in a project.
|
static String |
parseGlossaryFromGlossaryName(String glossaryName)
Deprecated.
Use the
GlossaryName class instead. |
static String |
parseLocationFromGlossaryName(String glossaryName)
Deprecated.
Use the
GlossaryName class instead. |
static String |
parseLocationFromLocationName(String locationName)
Deprecated.
Use the
LocationName class instead. |
static String |
parseProjectFromGlossaryName(String glossaryName)
Deprecated.
Use the
GlossaryName class instead. |
static String |
parseProjectFromLocationName(String locationName)
Deprecated.
Use the
LocationName class instead. |
void |
shutdown() |
void |
shutdownNow() |
com.google.cloud.translate.v3beta1.TranslateTextResponse |
translateText(com.google.cloud.translate.v3beta1.TranslateTextRequest request)
Translates input text and returns translated text.
|
UnaryCallable<com.google.cloud.translate.v3beta1.TranslateTextRequest,com.google.cloud.translate.v3beta1.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)
@Deprecated public static final String formatGlossaryName(String project, String location, String glossary)
GlossaryName
class instead.@Deprecated public static final String formatLocationName(String project, String location)
LocationName
class instead.@Deprecated public static final String parseProjectFromGlossaryName(String glossaryName)
GlossaryName
class instead.@Deprecated public static final String parseLocationFromGlossaryName(String glossaryName)
GlossaryName
class instead.@Deprecated public static final String parseGlossaryFromGlossaryName(String glossaryName)
GlossaryName
class instead.@Deprecated public static final String parseProjectFromLocationName(String locationName)
LocationName
class instead.@Deprecated public static final String parseLocationFromLocationName(String locationName)
LocationName
class instead.public static final TranslationServiceClient create() throws IOException
IOException
public 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 OperationsClient getOperationsClient()
public final com.google.cloud.translate.v3beta1.TranslateTextResponse translateText(com.google.cloud.translate.v3beta1.TranslateTextRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
List<String> contents = new ArrayList<>();
String targetLanguageCode = "";
TranslateTextRequest request = TranslateTextRequest.newBuilder()
.addAllContents(contents)
.setTargetLanguageCode(targetLanguageCode)
.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<com.google.cloud.translate.v3beta1.TranslateTextRequest,com.google.cloud.translate.v3beta1.TranslateTextResponse> translateTextCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
List<String> contents = new ArrayList<>();
String targetLanguageCode = "";
TranslateTextRequest request = TranslateTextRequest.newBuilder()
.addAllContents(contents)
.setTargetLanguageCode(targetLanguageCode)
.build();
ApiFuture<TranslateTextResponse> future = translationServiceClient.translateTextCallable().futureCall(request);
// Do something
TranslateTextResponse response = future.get();
}
public final com.google.cloud.translate.v3beta1.DetectLanguageResponse detectLanguage(String parent, String model, String mimeType)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
String model = "";
String mimeType = "";
DetectLanguageResponse response = translationServiceClient.detectLanguage(formattedParent, model, mimeType);
}
parent
- Optional. Only used when making regionalized call. Format:
projects/{project-id}/locations/{location-id}.
Only custom model within the same location-id can be used. Otherwise 400 is returned.
model
- Optional. The language detection model to be used.
projects/{project-id}/locations/{location-id}/models/language-detection/{model-id} If not
specified, default will be used.mimeType
- Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type is assumed to be "text/html".ApiException
- if the remote call failspublic final com.google.cloud.translate.v3beta1.DetectLanguageResponse detectLanguage(com.google.cloud.translate.v3beta1.DetectLanguageRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
DetectLanguageRequest request = DetectLanguageRequest.newBuilder().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<com.google.cloud.translate.v3beta1.DetectLanguageRequest,com.google.cloud.translate.v3beta1.DetectLanguageResponse> detectLanguageCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
DetectLanguageRequest request = DetectLanguageRequest.newBuilder().build();
ApiFuture<DetectLanguageResponse> future = translationServiceClient.detectLanguageCallable().futureCall(request);
// Do something
DetectLanguageResponse response = future.get();
}
public final com.google.cloud.translate.v3beta1.SupportedLanguages getSupportedLanguages(String parent, String displayLanguageCode, String model)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
String displayLanguageCode = "";
String model = "";
SupportedLanguages response = translationServiceClient.getSupportedLanguages(formattedParent, displayLanguageCode, model);
}
parent
- Optional. Used for making regionalized calls. Format:
projects/{project-id}/locations/{location-id}. For global calls, use
projects/{project-id}/locations/global. If missing, the call is treated as a global call.
Only custom model within the same location-id can be used. Otherwise 400 is returned.
displayLanguageCode
- Optional. The language to use to return localized, human readable
names of supported languages. If missing, default language is ENGLISH.model
- Optional. Get supported languages of this model. The format depends on model type:
1. Custom models: projects/{project-id}/locations/{location-id}/models/{model-id}. 2.
General (built-in) models: projects/{project-id}/locations/{location-id}/models/general/nmt
projects/{project-id}/locations/{location-id}/models/general/base Returns languages
supported by the specified model. If missing, we get supported languages of Google general
NMT model.ApiException
- if the remote call failspublic final com.google.cloud.translate.v3beta1.SupportedLanguages getSupportedLanguages(com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GetSupportedLanguagesRequest request = GetSupportedLanguagesRequest.newBuilder().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<com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest,com.google.cloud.translate.v3beta1.SupportedLanguages> getSupportedLanguagesCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
GetSupportedLanguagesRequest request = GetSupportedLanguagesRequest.newBuilder().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 OperationFuture<com.google.cloud.translate.v3beta1.BatchTranslateResponse,com.google.cloud.translate.v3beta1.BatchTranslateMetadata> batchTranslateTextAsync(com.google.cloud.translate.v3beta1.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()) {
String sourceLanguageCode = "";
List<String> targetLanguageCodes = new ArrayList<>();
List<InputConfig> inputConfigs = new ArrayList<>();
OutputConfig outputConfig = OutputConfig.newBuilder().build();
BatchTranslateTextRequest request = BatchTranslateTextRequest.newBuilder()
.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.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 OperationCallable<com.google.cloud.translate.v3beta1.BatchTranslateTextRequest,com.google.cloud.translate.v3beta1.BatchTranslateResponse,com.google.cloud.translate.v3beta1.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()) {
String sourceLanguageCode = "";
List<String> targetLanguageCodes = new ArrayList<>();
List<InputConfig> inputConfigs = new ArrayList<>();
OutputConfig outputConfig = OutputConfig.newBuilder().build();
BatchTranslateTextRequest request = BatchTranslateTextRequest.newBuilder()
.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 UnaryCallable<com.google.cloud.translate.v3beta1.BatchTranslateTextRequest,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()) {
String sourceLanguageCode = "";
List<String> targetLanguageCodes = new ArrayList<>();
List<InputConfig> inputConfigs = new ArrayList<>();
OutputConfig outputConfig = OutputConfig.newBuilder().build();
BatchTranslateTextRequest request = BatchTranslateTextRequest.newBuilder()
.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 OperationFuture<com.google.cloud.translate.v3beta1.Glossary,com.google.cloud.translate.v3beta1.CreateGlossaryMetadata> createGlossaryAsync(String parent, com.google.cloud.translate.v3beta1.Glossary glossary)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
Glossary response = translationServiceClient.createGlossaryAsync(formattedParent, glossary).get();
}
parent
- Required. The project name.glossary
- Required. The glossary to create.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 OperationFuture<com.google.cloud.translate.v3beta1.Glossary,com.google.cloud.translate.v3beta1.CreateGlossaryMetadata> createGlossaryAsync(com.google.cloud.translate.v3beta1.CreateGlossaryRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder()
.setParent(formattedParent)
.setGlossary(glossary)
.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 fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.cloud.translate.v3beta1.CreateGlossaryRequest,com.google.cloud.translate.v3beta1.Glossary,com.google.cloud.translate.v3beta1.CreateGlossaryMetadata> createGlossaryOperationCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder()
.setParent(formattedParent)
.setGlossary(glossary)
.build();
OperationFuture<Glossary, CreateGlossaryMetadata> future = translationServiceClient.createGlossaryOperationCallable().futureCall(request);
// Do something
Glossary response = future.get();
}
public final UnaryCallable<com.google.cloud.translate.v3beta1.CreateGlossaryRequest,Operation> createGlossaryCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
Glossary glossary = Glossary.newBuilder().build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder()
.setParent(formattedParent)
.setGlossary(glossary)
.build();
ApiFuture<Operation> future = translationServiceClient.createGlossaryCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(String parent, String filter)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedParent = TranslationServiceClient.formatLocationName("[PROJECT]", "[LOCATION]");
String filter = "";
for (Glossary element : translationServiceClient.listGlossaries(formattedParent, filter).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The name of the project from which to list all of the glossaries.filter
- Optional. Filter specifying constraints of a list operation. For example,
`tags.glossary_name="products*"`. If missing, no filtering is performed.ApiException
- if the remote call failspublic final TranslationServiceClient.ListGlossariesPagedResponse listGlossaries(com.google.cloud.translate.v3beta1.ListGlossariesRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
ListGlossariesRequest request = ListGlossariesRequest.newBuilder().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<com.google.cloud.translate.v3beta1.ListGlossariesRequest,TranslationServiceClient.ListGlossariesPagedResponse> listGlossariesPagedCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
ListGlossariesRequest request = ListGlossariesRequest.newBuilder().build();
ApiFuture<ListGlossariesPagedResponse> future = translationServiceClient.listGlossariesPagedCallable().futureCall(request);
// Do something
for (Glossary element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.cloud.translate.v3beta1.ListGlossariesRequest,com.google.cloud.translate.v3beta1.ListGlossariesResponse> listGlossariesCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
ListGlossariesRequest request = ListGlossariesRequest.newBuilder().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 com.google.cloud.translate.v3beta1.Glossary getGlossary(String name)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
Glossary response = translationServiceClient.getGlossary(formattedName);
}
name
- Required. The name of the glossary to retrieve.ApiException
- if the remote call failspublic final com.google.cloud.translate.v3beta1.Glossary getGlossary(com.google.cloud.translate.v3beta1.GetGlossaryRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
GetGlossaryRequest request = GetGlossaryRequest.newBuilder()
.setName(formattedName)
.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<com.google.cloud.translate.v3beta1.GetGlossaryRequest,com.google.cloud.translate.v3beta1.Glossary> getGlossaryCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
GetGlossaryRequest request = GetGlossaryRequest.newBuilder()
.setName(formattedName)
.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 OperationFuture<com.google.cloud.translate.v3beta1.DeleteGlossaryResponse,com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata> deleteGlossaryAsync(String name)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(formattedName).get();
}
name
- Required. The name of the glossary to delete.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 OperationFuture<com.google.cloud.translate.v3beta1.DeleteGlossaryResponse,com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata> deleteGlossaryAsync(com.google.cloud.translate.v3beta1.DeleteGlossaryRequest request)
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder()
.setName(formattedName)
.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 fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.cloud.translate.v3beta1.DeleteGlossaryRequest,com.google.cloud.translate.v3beta1.DeleteGlossaryResponse,com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata> deleteGlossaryOperationCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder()
.setName(formattedName)
.build();
OperationFuture<DeleteGlossaryResponse, DeleteGlossaryMetadata> future = translationServiceClient.deleteGlossaryOperationCallable().futureCall(request);
// Do something
DeleteGlossaryResponse response = future.get();
}
public final UnaryCallable<com.google.cloud.translate.v3beta1.DeleteGlossaryRequest,Operation> deleteGlossaryCallable()
Sample code:
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
String formattedName = TranslationServiceClient.formatGlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]");
DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder()
.setName(formattedName)
.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 © 2019 Google LLC. All rights reserved.