Search in sources :

Example 1 with LanguageListOption

use of com.google.cloud.translate.Translate.LanguageListOption 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 2 with LanguageListOption

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

the class TranslateTest method testListOptions.

@Test
public void testListOptions() {
    // target language
    LanguageListOption listOption = LanguageListOption.targetLanguage(LANGUAGE);
    assertEquals(TranslateRpc.Option.TARGET_LANGUAGE, listOption.getRpcOption());
    assertEquals(LANGUAGE, listOption.getValue());
}
Also used : LanguageListOption(com.google.cloud.translate.Translate.LanguageListOption) Test(org.junit.Test)

Aggregations

LanguageListOption (com.google.cloud.translate.Translate.LanguageListOption)2 Language (com.google.cloud.translate.Language)1 Translate (com.google.cloud.translate.Translate)1 Test (org.junit.Test)1