Search in sources :

Example 1 with SupportedLanguages

use of com.google.cloud.translate.v3beta1.SupportedLanguages 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);
    }
}
Also used : GetSupportedLanguagesRequest(com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest) SupportedLanguages(com.google.cloud.translate.v3beta1.SupportedLanguages) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) SupportedLanguage(com.google.cloud.translate.v3beta1.SupportedLanguage) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 2 with SupportedLanguages

use of com.google.cloud.translate.v3beta1.SupportedLanguages 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);
    }
}
Also used : GetSupportedLanguagesRequest(com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest) SupportedLanguages(com.google.cloud.translate.v3beta1.SupportedLanguages) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) SupportedLanguage(com.google.cloud.translate.v3beta1.SupportedLanguage) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Aggregations

GetSupportedLanguagesRequest (com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest)2 LocationName (com.google.cloud.translate.v3beta1.LocationName)2 SupportedLanguage (com.google.cloud.translate.v3beta1.SupportedLanguage)2 SupportedLanguages (com.google.cloud.translate.v3beta1.SupportedLanguages)2 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)2