17
17
package com .example .translate ;
18
18
19
19
// [START translate_v3_translate_text]
20
+ // [START translate_v3_translate_text_0]
21
+ // Imports the Google Cloud Translation library.
20
22
import com .google .cloud .translate .v3 .LocationName ;
21
23
import com .google .cloud .translate .v3 .TranslateTextRequest ;
22
24
import com .google .cloud .translate .v3 .TranslateTextResponse ;
23
25
import com .google .cloud .translate .v3 .Translation ;
24
26
import com .google .cloud .translate .v3 .TranslationServiceClient ;
25
27
import java .io .IOException ;
26
28
29
+ // [END translate_v3_translate_text_0]
30
+
27
31
public class TranslateText {
28
32
33
+ // [START translate_v3_translate_text_1]
34
+ // Set and pass variables to overloaded translateText() method for translation.
29
35
public static void translateText () throws IOException {
30
36
// TODO(developer): Replace these variables before running the sample.
31
37
String projectId = "YOUR-PROJECT-ID" ;
@@ -34,8 +40,10 @@ public static void translateText() throws IOException {
34
40
String text = "your-text" ;
35
41
translateText (projectId , targetLanguage , text );
36
42
}
43
+ // [END translate_v3_translate_text_1]
37
44
38
- // Translating Text
45
+ // [START translate_v3_translate_text_2]
46
+ // Translate text to target language.
39
47
public static void translateText (String projectId , String targetLanguage , String text )
40
48
throws IOException {
41
49
@@ -65,5 +73,6 @@ public static void translateText(String projectId, String targetLanguage, String
65
73
}
66
74
}
67
75
}
76
+ // [END translate_v3_translate_text_2]
68
77
}
69
78
// [END translate_v3_translate_text]
0 commit comments