From 6e4f7f22ab39c2a0ae027d08ee8e31e25847bb77 Mon Sep 17 00:00:00 2001 From: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Date: Mon, 21 May 2018 11:35:42 -0700 Subject: [PATCH] Update Translate Samples for Samples Tracker (#1105) * Add translate_translate_text tags. translate_translate_text * Add translate_text_with_model tags. * Add translate_list_codes tags. * Add translate_list_language_names tags. * Add translate_detect_language tags. --- .../example/cloud/translate/samples/TranslateText.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java b/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java index e294c473fc0..2281f37845b 100644 --- a/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java +++ b/translate/src/main/java/com/example/cloud/translate/samples/TranslateText.java @@ -35,6 +35,7 @@ public class TranslateText { * @param sourceText source text to be detected for language * @param out print stream */ + //[START translate_detect_language] public static void detectLanguage(String sourceText, PrintStream out) { Translate translate = createTranslateService(); List detections = translate.detect(ImmutableList.of(sourceText)); @@ -43,6 +44,7 @@ public static void detectLanguage(String sourceText, PrintStream out) { out.printf("\t%s\n", detection); } } + //[END translate_detect_language] /** * Translates the source text in any language to English. @@ -50,12 +52,14 @@ public static void detectLanguage(String sourceText, PrintStream out) { * @param sourceText source text to be translated * @param out print stream */ + //[START translate_translate_text] public static void translateText(String sourceText, PrintStream out) { Translate translate = createTranslateService(); Translation translation = translate.translate(sourceText); out.printf("Source Text:\n\t%s\n", sourceText); out.printf("Translated Text:\n\t%s\n", translation.getTranslatedText()); } + //[END translate_translate_text] /** * Translate the source text from source to target language. @@ -66,6 +70,7 @@ public static void translateText(String sourceText, PrintStream out) { * @param targetLang target language of translated text * @param out print stream */ + //[START translate_text_with_model] public static void translateTextWithOptionsAndModel( String sourceText, String sourceLang, @@ -84,6 +89,7 @@ public static void translateTextWithOptionsAndModel( out.printf("TranslatedText:\n\tLang: %s, Text: %s\n", targetLang, translation.getTranslatedText()); } + //[END translate_text_with_model] /** @@ -116,6 +122,8 @@ public static void translateTextWithOptions( * @param out print stream * @param tgtLang optional target language */ + //[START translate_list_language_names] + //[START translate_list_codes] public static void displaySupportedLanguages(PrintStream out, Optional tgtLang) { Translate translate = createTranslateService(); LanguageListOption target = LanguageListOption.targetLanguage(tgtLang.orElse("en")); @@ -125,6 +133,8 @@ public static void displaySupportedLanguages(PrintStream out, Optional t out.printf("Name: %s, Code: %s\n", language.getName(), language.getCode()); } } + //[END translate_list_codes] + //[END translate_list_language_names] /** * Create Google Translate API Service.