@@ -116,15 +116,35 @@ public static TranslateOption format(String format) {
116
116
*
117
117
* <p>Example of listing supported languages, localized according to
118
118
* {@link TranslateOptions#getTargetLanguage()}:
119
- * <pre> {@code
119
+ * <!--SNIPPET translate_list_codes-->
120
+ * <pre>{@code
121
+ * // TODO(developer): Uncomment these lines.
122
+ * // import com.google.cloud.translate.*;
123
+ * // Translate translate = TranslateOptions.getDefaultInstance().getService();
124
+ *
120
125
* List<Language> languages = translate.listSupportedLanguages();
126
+ *
127
+ * for (Language language : languages) {
128
+ * System.out.printf("Name: %s, Code: %s\n", language.getName(), language.getCode());
129
+ * }
121
130
* }</pre>
131
+ * <!--SNIPPET translate_list_codes-->
122
132
*
123
133
* <p>Example of listing supported languages, localized according to a provided language:
124
- * <pre> {@code
134
+ * <!--SNIPPET translate_list_language_names-->
135
+ * <pre>{@code
136
+ * // TODO(developer): Uncomment these lines.
137
+ * // import com.google.cloud.translate.*;
138
+ * // Translate translate = TranslateOptions.getDefaultInstance().getService();
139
+ *
125
140
* List<Language> languages = translate.listSupportedLanguages(
126
- * LanguageListOption.targetLanguage("es"));
141
+ * Translate.LanguageListOption.targetLanguage("es"));
142
+ *
143
+ * for (Language language : languages) {
144
+ * System.out.printf("Name: %s, Code: %s\n", language.getName(), language.getCode());
145
+ * }
127
146
* }</pre>
147
+ * <!--SNIPPET translate_list_language_names-->
128
148
*
129
149
*/
130
150
List <Language > listSupportedLanguages (LanguageListOption ... options );
@@ -133,13 +153,24 @@ public static TranslateOption format(String format) {
133
153
* Detects the language of the provided texts.
134
154
*
135
155
* <p>Example of detecting the language of some texts:
136
- * <pre> {@code
156
+ * <!--SNIPPET translate_detect_language-->
157
+ * <pre>{@code
158
+ * // TODO(developer): Uncomment these lines.
159
+ * // import com.google.cloud.translate.*;
160
+ * // Translate translate = TranslateOptions.getDefaultInstance().getService();
161
+ *
137
162
* List<String> texts = new LinkedList<>();
138
163
* texts.add("Hello, World!");
139
164
* texts.add("¡Hola Mundo!");
140
165
* List<Detection> detections = translate.detect(texts);
141
- * }</pre>
142
166
*
167
+ * System.out.println("Language(s) detected:");
168
+ * for (Detection detection : detections) {
169
+ * System.out.printf("\t%s\n", detection);
170
+ * }
171
+ * }</pre>
172
+ * <!--SNIPPET translate_detect_language-->
173
+
143
174
* @param texts the texts for which language should be detected
144
175
* @return a list of objects containing information on the language detection, one for each
145
176
* provided text, in order
@@ -150,9 +181,11 @@ public static TranslateOption format(String format) {
150
181
* Detects the language of the provided texts.
151
182
*
152
183
* <p>Example of detecting the language of some texts:
153
- * <pre> {@code
184
+ * <!--SNIPPET translate_detect_language_array-->
185
+ * <pre>{@code
154
186
* List<Detection> detections = translate.detect("Hello, World!", "¡Hola Mundo!");
155
187
* }</pre>
188
+ * <!--SNIPPET translate_detect_language_array-->
156
189
*
157
190
* @param texts the texts for which language should be detected
158
191
* @return a list of objects containing information on the language detection, one for each
@@ -165,9 +198,11 @@ public static TranslateOption format(String format) {
165
198
* language detection.
166
199
*
167
200
* <p>Example of detecting the language of a text:
168
- * <pre> {@code
201
+ * <!--SNIPPET translate_detect_language_string-->
202
+ * <pre>{@code
169
203
* Detection detection = translate.detect("Hello, World!");
170
204
* }</pre>
205
+ * <!--SNIPPET translate_detect_language_string-->
171
206
*
172
207
*/
173
208
Detection detect (String text );
@@ -176,20 +211,26 @@ public static TranslateOption format(String format) {
176
211
* Translates the provided texts.
177
212
*
178
213
* <p>Example of translating some texts:
179
- * <pre> {@code
214
+ * <!--SNIPPET translateTexts-->
215
+ * <pre>{@code
180
216
* List<String> texts = new LinkedList<>();
181
217
* texts.add("Hello, World!");
182
218
* texts.add("¡Hola Mundo!");
183
219
* List<Translation> translations = translate.translate(texts);
184
220
* }</pre>
221
+ * <!--SNIPPET translateTexts-->
185
222
*
186
223
* <p>Example of translating some texts, specifying source and target language:
187
- * <pre> {@code
224
+ * <!--SNIPPET translateTextsWithOptions-->
225
+ * <pre>{@code
188
226
* List<String> texts = new LinkedList<>();
189
227
* texts.add("¡Hola Mundo!");
190
- * List<Translation> translations = translate.translate(texts,
191
- * TranslateOption.sourceLanguage("es"), TranslateOption.targetLanguage("de"));
228
+ * List<Translation> translations = translate.translate(
229
+ * texts,
230
+ * Translate.TranslateOption.sourceLanguage("es"),
231
+ * Translate.TranslateOption.targetLanguage("de"));
192
232
* }</pre>
233
+ * <!--SNIPPET translateTextsWithOptions-->
193
234
*
194
235
* @param texts the texts to translate
195
236
* @return a list of objects containing information on the language translation, one for each
@@ -200,18 +241,35 @@ public static TranslateOption format(String format) {
200
241
List <Translation > translate (List <String > texts , TranslateOption ... options );
201
242
202
243
/**
203
- * Translates the provided texts .
244
+ * Translates the provided text .
204
245
*
205
246
* <p>Example of translating a text:
206
- * <pre> {@code
247
+ * <!--SNIPPET translate_translate_text-->
248
+ * <pre>{@code
249
+ * // TODO(developer): Uncomment these lines.
250
+ * // import com.google.cloud.translate.*;
251
+ * // Translate translate = TranslateOptions.getDefaultInstance().getService();
252
+ *
207
253
* Translation translation = translate.translate("¡Hola Mundo!");
254
+ * System.out.printf("Translated Text:\n\t%s\n", translation.getTranslatedText());
208
255
* }</pre>
256
+ * <!--SNIPPET translate_translate_text-->
257
+ *
258
+ * <p>Example of translating a text, specifying source and target language and premium model:
259
+ * <!--SNIPPET translate_text_with_model-->
260
+ * <pre>{@code
261
+ * Translation translation = translate.translate(
262
+ * "Hola Mundo!",
263
+ * Translate.TranslateOption.sourceLanguage("es"),
264
+ * Translate.TranslateOption.targetLanguage("de"),
265
+ * // Use "base" for standard edition, "nmt" for the premium model.
266
+ * Translate.TranslateOption.model("nmt"));
209
267
*
210
- * <p>Example of translating a text, specifying source and target language:
211
- * <pre> {@code
212
- * Translation translation = translate.translate("¡Hola Mundo!",
213
- * TranslateOption.sourceLanguage("es"), TranslateOption.targetLanguage("de"));
268
+ * System.out.printf(
269
+ * "TranslatedText:\nText: %s\n",
270
+ * translation.getTranslatedText());
214
271
* }</pre>
272
+ * <!--SNIPPET translate_text_with_model-->
215
273
*
216
274
* @param text the text to translate
217
275
* @return an object containing information on the language translation
0 commit comments