use of com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest in project google-cloud-java by GoogleCloudPlatform.
the class TranslateSnippetsBeta method listSupportedLanguages.
/**
* Lists all the supported language codes.
*
* @param projectId - Id of the project.
* @param location - location name.
*/
// [START translate_list_codes_beta]
static SupportedLanguages listSupportedLanguages(String projectId, String location) {
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
GetSupportedLanguagesRequest getSupportedLanguagesRequest = GetSupportedLanguagesRequest.newBuilder().setParent(locationName.toString()).build();
// Call the API
ApiFuture<SupportedLanguages> future = translationServiceClient.getSupportedLanguagesCallable().futureCall(getSupportedLanguagesRequest);
SupportedLanguages response = future.get();
List<SupportedLanguage> languages = response.getLanguagesList();
for (SupportedLanguage language : languages) {
System.out.printf("Code: %s\n", language.getLanguageCode());
}
return response;
} catch (Exception e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest in project google-cloud-java by GoogleCloudPlatform.
the class TranslateSnippetsBeta method listSupportedLanguagesWithTarget.
// [END translate_list_codes_beta]
/**
* Lists all the supported language names and codes.
*
* @param projectId - Id of the project.
* @param location - location name.
*/
// [START translate_list_language_names_beta]
static SupportedLanguages listSupportedLanguagesWithTarget(String projectId, String location) {
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
GetSupportedLanguagesRequest getSupportedLanguagesRequest = GetSupportedLanguagesRequest.newBuilder().setParent(locationName.toString()).setDisplayLanguageCode("en-US").build();
// Call the API
ApiFuture<SupportedLanguages> future = translationServiceClient.getSupportedLanguagesCallable().futureCall(getSupportedLanguagesRequest);
SupportedLanguages response = future.get();
List<SupportedLanguage> languages = response.getLanguagesList();
for (SupportedLanguage language : languages) {
System.out.printf("Name: %s, Code: %s\n", language.getDisplayName(), language.getLanguageCode());
}
return response;
} catch (Exception e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
Aggregations