Skip to content

Commit

Permalink
Update Translate Samples for Samples Tracker (#1105)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kurtisvg authored May 21, 2018
1 parent c7a8a5a commit 6e4f7f2
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Detection> detections = translate.detect(ImmutableList.of(sourceText));
Expand All @@ -43,19 +44,22 @@ 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.
*
* @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.
Expand All @@ -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,
Expand All @@ -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]


/**
Expand Down Expand Up @@ -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<String> tgtLang) {
Translate translate = createTranslateService();
LanguageListOption target = LanguageListOption.targetLanguage(tgtLang.orElse("en"));
Expand All @@ -125,6 +133,8 @@ public static void displaySupportedLanguages(PrintStream out, Optional<String> 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.
Expand Down

0 comments on commit 6e4f7f2

Please sign in to comment.