1717package com .example .translate ;
1818
1919// [START translate_v3_translate_text]
20+ // [START translate_v3_translate_text_0]
21+ // Imports the Google Cloud Translation library.
2022import com .google .cloud .translate .v3 .LocationName ;
2123import com .google .cloud .translate .v3 .TranslateTextRequest ;
2224import com .google .cloud .translate .v3 .TranslateTextResponse ;
2325import com .google .cloud .translate .v3 .Translation ;
2426import com .google .cloud .translate .v3 .TranslationServiceClient ;
2527import java .io .IOException ;
2628
29+ // [END translate_v3_translate_text_0]
30+
2731public class TranslateText {
2832
33+ // [START translate_v3_translate_text_1]
34+ // Set and pass variables to overloaded translateText() method for translation.
2935 public static void translateText () throws IOException {
3036 // TODO(developer): Replace these variables before running the sample.
3137 String projectId = "YOUR-PROJECT-ID" ;
@@ -34,8 +40,10 @@ public static void translateText() throws IOException {
3440 String text = "your-text" ;
3541 translateText (projectId , targetLanguage , text );
3642 }
43+ // [END translate_v3_translate_text_1]
3744
38- // Translating Text
45+ // [START translate_v3_translate_text_2]
46+ // Translate text to target language.
3947 public static void translateText (String projectId , String targetLanguage , String text )
4048 throws IOException {
4149
@@ -65,5 +73,6 @@ public static void translateText(String projectId, String targetLanguage, String
6573 }
6674 }
6775 }
76+ // [END translate_v3_translate_text_2]
6877}
6978// [END translate_v3_translate_text]
0 commit comments