Search in sources :

Example 1 with Language

use of com.google.cloud.translate.Language in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateTest method testListSupportedLanguagesWithOptions.

@Test
public void testListSupportedLanguagesWithOptions() {
    Set<String> supportedLanguages = new HashSet<>();
    List<Language> languages = TRANSLATE.listSupportedLanguages(LanguageListOption.targetLanguage("es"));
    for (Language language : languages) {
        supportedLanguages.add(language.getCode());
        assertNotNull(language.getName());
    }
    for (String code : LANGUAGES) {
        assertTrue(supportedLanguages.contains(code));
    }
}
Also used : Language(com.google.cloud.translate.Language) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Language

use of com.google.cloud.translate.Language in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateTest method testListSupportedLanguages.

@Test
public void testListSupportedLanguages() {
    Set<String> supportedLanguages = new HashSet<>();
    List<Language> languages = TRANSLATE.listSupportedLanguages();
    for (Language language : languages) {
        supportedLanguages.add(language.getCode());
        assertNotNull(language.getName());
    }
    for (String code : LANGUAGES) {
        assertTrue(supportedLanguages.contains(code));
    }
}
Also used : Language(com.google.cloud.translate.Language) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Language

use of com.google.cloud.translate.Language in project java-docs-samples by GoogleCloudPlatform.

the class TranslateText method displaySupportedLanguages.

/**
 * Displays a list of supported languages and codes.
 *
 * @param out print stream
 * @param tgtLang optional target language
 */
public static void displaySupportedLanguages(PrintStream out, Optional<String> tgtLang) {
    Translate translate = createTranslateService();
    LanguageListOption target = LanguageListOption.targetLanguage(tgtLang.orElse("en"));
    List<Language> languages = translate.listSupportedLanguages(target);
    for (Language language : languages) {
        out.printf("Name: %s, Code: %s\n", language.getName(), language.getCode());
    }
}
Also used : Language(com.google.cloud.translate.Language) LanguageListOption(com.google.cloud.translate.Translate.LanguageListOption) Translate(com.google.cloud.translate.Translate)

Example 4 with Language

use of com.google.cloud.translate.Language in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateSnippets method testListSupportedLanguages.

@Test
public void testListSupportedLanguages() {
    // [START translate_list_codes]
    // TODO(developer): Uncomment these lines.
    // import com.google.cloud.translate.*;
    // Translate translate = TranslateOptions.getDefaultInstance().getService();
    List<Language> languages = translate.listSupportedLanguages();
    for (Language language : languages) {
        System.out.printf("Name: %s, Code: %s\n", language.getName(), language.getCode());
    }
    // [END translate_list_codes]
    Set<String> supportedLanguages = new HashSet<>();
    for (Language language : languages) {
        supportedLanguages.add(language.getCode());
        assertNotNull(language.getName());
    }
    for (String code : LANGUAGES) {
        assertTrue(supportedLanguages.contains(code));
    }
}
Also used : Language(com.google.cloud.translate.Language) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Language

use of com.google.cloud.translate.Language in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateSnippets method testListSupportedLanguagesWithTarget.

@Test
public void testListSupportedLanguagesWithTarget() {
    // [START translate_list_language_names]
    // TODO(developer): Uncomment these lines.
    // import com.google.cloud.translate.*;
    // Translate translate = TranslateOptions.getDefaultInstance().getService();
    List<Language> languages = translate.listSupportedLanguages(Translate.LanguageListOption.targetLanguage("es"));
    for (Language language : languages) {
        System.out.printf("Name: %s, Code: %s\n", language.getName(), language.getCode());
    }
    // [END translate_list_language_names]
    Set<String> supportedLanguages = new HashSet<>();
    for (Language language : languages) {
        supportedLanguages.add(language.getCode());
        assertNotNull(language.getName());
    }
    for (String code : LANGUAGES) {
        assertTrue(supportedLanguages.contains(code));
    }
}
Also used : Language(com.google.cloud.translate.Language) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Language (com.google.cloud.translate.Language)5 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Translate (com.google.cloud.translate.Translate)1 LanguageListOption (com.google.cloud.translate.Translate.LanguageListOption)1