@@ -35,6 +35,7 @@ public class TranslateText {
35
35
* @param sourceText source text to be detected for language
36
36
* @param out print stream
37
37
*/
38
+ //[START translate_detect_language]
38
39
public static void detectLanguage (String sourceText , PrintStream out ) {
39
40
Translate translate = createTranslateService ();
40
41
List <Detection > detections = translate .detect (ImmutableList .of (sourceText ));
@@ -43,19 +44,22 @@ public static void detectLanguage(String sourceText, PrintStream out) {
43
44
out .printf ("\t %s\n " , detection );
44
45
}
45
46
}
47
+ //[END translate_detect_language]
46
48
47
49
/**
48
50
* Translates the source text in any language to English.
49
51
*
50
52
* @param sourceText source text to be translated
51
53
* @param out print stream
52
54
*/
55
+ //[START translate_translate_text]
53
56
public static void translateText (String sourceText , PrintStream out ) {
54
57
Translate translate = createTranslateService ();
55
58
Translation translation = translate .translate (sourceText );
56
59
out .printf ("Source Text:\n \t %s\n " , sourceText );
57
60
out .printf ("Translated Text:\n \t %s\n " , translation .getTranslatedText ());
58
61
}
62
+ //[END translate_translate_text]
59
63
60
64
/**
61
65
* Translate the source text from source to target language.
@@ -66,6 +70,7 @@ public static void translateText(String sourceText, PrintStream out) {
66
70
* @param targetLang target language of translated text
67
71
* @param out print stream
68
72
*/
73
+ //[START translate_text_with_model]
69
74
public static void translateTextWithOptionsAndModel (
70
75
String sourceText ,
71
76
String sourceLang ,
@@ -84,6 +89,7 @@ public static void translateTextWithOptionsAndModel(
84
89
out .printf ("TranslatedText:\n \t Lang: %s, Text: %s\n " , targetLang ,
85
90
translation .getTranslatedText ());
86
91
}
92
+ //[END translate_text_with_model]
87
93
88
94
89
95
/**
@@ -116,6 +122,8 @@ public static void translateTextWithOptions(
116
122
* @param out print stream
117
123
* @param tgtLang optional target language
118
124
*/
125
+ //[START translate_list_language_names]
126
+ //[START translate_list_codes]
119
127
public static void displaySupportedLanguages (PrintStream out , Optional <String > tgtLang ) {
120
128
Translate translate = createTranslateService ();
121
129
LanguageListOption target = LanguageListOption .targetLanguage (tgtLang .orElse ("en" ));
@@ -125,6 +133,8 @@ public static void displaySupportedLanguages(PrintStream out, Optional<String> t
125
133
out .printf ("Name: %s, Code: %s\n " , language .getName (), language .getCode ());
126
134
}
127
135
}
136
+ //[END translate_list_codes]
137
+ //[END translate_list_language_names]
128
138
129
139
/**
130
140
* Create Google Translate API Service.
0 commit comments