Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Translate Samples for Samples Tracker #1105

Merged
merged 5 commits into from
May 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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