Skip to content

Commit 149987e

Browse files
authored
Move Translate snippets to test file, use new snippets.go for inclusion. (googleapis#3527)
Updates snippets.go utility to Deindent and Indent by one space. Updates to samples which are included in the docs to meet our cdpe-snippets-rubric (show imports, show client construction, show how to use the resulting object). I will follow-up with a PR to java-docs-samples to remove any redundant snippets from that repo. Why move to a test file? We are considering moving all snippets-style samples to test files to avoid redundant work involved with keeping snippets separate from test files. The important thing for snippets is that they are runnable and copy-pastable. Ran snippets utility to include snippets in JavaDoc. ./utilities/snippets \ ./google-cloud-examples/src/test/java/com/google/cloud/examples/translate/snippets/ITTranslateSnippets.java \ ./google-cloud-clients/google-cloud-translate/src/main/java/com/google/cloud/translate/Translate.java
1 parent 10ae878 commit 149987e

File tree

4 files changed

+184
-188
lines changed

4 files changed

+184
-188
lines changed

google-cloud-clients/google-cloud-translate/src/main/java/com/google/cloud/translate/Translate.java

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,35 @@ public static TranslateOption format(String format) {
116116
*
117117
* <p>Example of listing supported languages, localized according to
118118
* {@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+
*
120125
* 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+
* }
121130
* }</pre>
131+
* <!--SNIPPET translate_list_codes-->
122132
*
123133
* <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+
*
125140
* 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+
* }
127146
* }</pre>
147+
* <!--SNIPPET translate_list_language_names-->
128148
*
129149
*/
130150
List<Language> listSupportedLanguages(LanguageListOption... options);
@@ -133,13 +153,24 @@ public static TranslateOption format(String format) {
133153
* Detects the language of the provided texts.
134154
*
135155
* <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+
*
137162
* List<String> texts = new LinkedList<>();
138163
* texts.add("Hello, World!");
139164
* texts.add("¡Hola Mundo!");
140165
* List<Detection> detections = translate.detect(texts);
141-
* }</pre>
142166
*
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+
143174
* @param texts the texts for which language should be detected
144175
* @return a list of objects containing information on the language detection, one for each
145176
* provided text, in order
@@ -150,9 +181,11 @@ public static TranslateOption format(String format) {
150181
* Detects the language of the provided texts.
151182
*
152183
* <p>Example of detecting the language of some texts:
153-
* <pre> {@code
184+
* <!--SNIPPET translate_detect_language_array-->
185+
* <pre>{@code
154186
* List<Detection> detections = translate.detect("Hello, World!", "¡Hola Mundo!");
155187
* }</pre>
188+
* <!--SNIPPET translate_detect_language_array-->
156189
*
157190
* @param texts the texts for which language should be detected
158191
* @return a list of objects containing information on the language detection, one for each
@@ -165,9 +198,11 @@ public static TranslateOption format(String format) {
165198
* language detection.
166199
*
167200
* <p>Example of detecting the language of a text:
168-
* <pre> {@code
201+
* <!--SNIPPET translate_detect_language_string-->
202+
* <pre>{@code
169203
* Detection detection = translate.detect("Hello, World!");
170204
* }</pre>
205+
* <!--SNIPPET translate_detect_language_string-->
171206
*
172207
*/
173208
Detection detect(String text);
@@ -176,20 +211,26 @@ public static TranslateOption format(String format) {
176211
* Translates the provided texts.
177212
*
178213
* <p>Example of translating some texts:
179-
* <pre> {@code
214+
* <!--SNIPPET translateTexts-->
215+
* <pre>{@code
180216
* List<String> texts = new LinkedList<>();
181217
* texts.add("Hello, World!");
182218
* texts.add("¡Hola Mundo!");
183219
* List<Translation> translations = translate.translate(texts);
184220
* }</pre>
221+
* <!--SNIPPET translateTexts-->
185222
*
186223
* <p>Example of translating some texts, specifying source and target language:
187-
* <pre> {@code
224+
* <!--SNIPPET translateTextsWithOptions-->
225+
* <pre>{@code
188226
* List<String> texts = new LinkedList<>();
189227
* 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"));
192232
* }</pre>
233+
* <!--SNIPPET translateTextsWithOptions-->
193234
*
194235
* @param texts the texts to translate
195236
* @return a list of objects containing information on the language translation, one for each
@@ -200,18 +241,35 @@ public static TranslateOption format(String format) {
200241
List<Translation> translate(List<String> texts, TranslateOption... options);
201242

202243
/**
203-
* Translates the provided texts.
244+
* Translates the provided text.
204245
*
205246
* <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+
*
207253
* Translation translation = translate.translate("¡Hola Mundo!");
254+
* System.out.printf("Translated Text:\n\t%s\n", translation.getTranslatedText());
208255
* }</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"));
209267
*
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());
214271
* }</pre>
272+
* <!--SNIPPET translate_text_with_model-->
215273
*
216274
* @param text the text to translate
217275
* @return an object containing information on the language translation

google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/TranslateSnippets.java

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)