File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,18 @@ function main(
27
27
// const location = 'global';
28
28
// const text = 'text to translate';
29
29
30
+ // [START translate_v3_translate_text_0]
30
31
// Imports the Google Cloud Translation library
31
32
const { TranslationServiceClient} = require ( '@google-cloud/translate' ) ;
33
+ // [END translate_v3_translate_text_0]
32
34
35
+ // [START translate_v3_translate_text_1]
33
36
// Instantiates a client
34
37
const translationClient = new TranslationServiceClient ( ) ;
38
+ // [END translate_v3_translate_text_1]
39
+
35
40
async function translateText ( ) {
41
+ // [START translate_v3_translate_text_2]
36
42
// Construct request
37
43
const request = {
38
44
parent : `projects/${ projectId } /locations/${ location } ` ,
@@ -41,13 +47,16 @@ function main(
41
47
sourceLanguageCode : 'en' ,
42
48
targetLanguageCode : 'sr-Latn' ,
43
49
} ;
50
+ // [END translate_v3_translate_text_2]
44
51
52
+ // [START translate_v3_translate_text_3]
45
53
// Run request
46
54
const [ response ] = await translationClient . translateText ( request ) ;
47
55
48
56
for ( const translation of response . translations ) {
49
57
console . log ( `Translation: ${ translation . translatedText } ` ) ;
50
58
}
59
+ // [END translate_v3_translate_text_3]
51
60
}
52
61
53
62
translateText ( ) ;
You can’t perform that action at this time.
0 commit comments