use of com.google.cloud.translate.v3.SupportedLanguage 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.v3.SupportedLanguage 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);
}
}
use of com.google.cloud.translate.v3.SupportedLanguage in project java-translate by googleapis.
the class GetSupportedLanguages method getSupportedLanguages.
// Getting a list of supported language codes
public static void getSupportedLanguages(String projectId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (TranslationServiceClient client = TranslationServiceClient.create()) {
// Supported Locations: `global`, [glossary location], or [model location]
// Glossaries must be hosted in `us-central1`
// Custom Models must use the same location as your model. (us-central1)
LocationName parent = LocationName.of(projectId, "global");
GetSupportedLanguagesRequest request = GetSupportedLanguagesRequest.newBuilder().setParent(parent.toString()).build();
SupportedLanguages response = client.getSupportedLanguages(request);
// List language codes of supported languages
for (SupportedLanguage language : response.getLanguagesList()) {
System.out.printf("Language Code: %s\n", language.getLanguageCode());
}
}
}
use of com.google.cloud.translate.v3.SupportedLanguage in project java-translate by googleapis.
the class GetSupportedLanguagesForTarget method getSupportedLanguagesForTarget.
// Listing supported languages with target language name
public static void getSupportedLanguagesForTarget(String projectId, String languageCode) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (TranslationServiceClient client = TranslationServiceClient.create()) {
// Supported Locations: `global`, [glossary location], or [model location]
// Glossaries must be hosted in `us-central1`
// Custom Models must use the same location as your model. (us-central1)
LocationName parent = LocationName.of(projectId, "global");
GetSupportedLanguagesRequest request = GetSupportedLanguagesRequest.newBuilder().setParent(parent.toString()).setDisplayLanguageCode(languageCode).build();
SupportedLanguages response = client.getSupportedLanguages(request);
// List language codes of supported languages
for (SupportedLanguage language : response.getLanguagesList()) {
System.out.printf("Language Code: %s\n", language.getLanguageCode());
System.out.printf("Display Name: %s\n", language.getDisplayName());
}
}
}
Aggregations