Search in sources :

Example 1 with SupportedLanguage

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);
    }
}
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 SupportedLanguage

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);
    }
}
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 3 with SupportedLanguage

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

Example 4 with SupportedLanguage

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

Aggregations

GetSupportedLanguagesRequest (com.google.cloud.translate.v3.GetSupportedLanguagesRequest)2 LocationName (com.google.cloud.translate.v3.LocationName)2 SupportedLanguage (com.google.cloud.translate.v3.SupportedLanguage)2 SupportedLanguages (com.google.cloud.translate.v3.SupportedLanguages)2 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)2 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