@@ -21,42 +21,41 @@ function main(
2121) {
2222 // [START translate_v3_translate_text]
2323 /**
24- * TODO(developer): Uncomment these variables before running the sample.
24+ * TODO(developer): Uncomment these variables before running the sample
2525 */
2626 // const projectId = 'YOUR_PROJECT_ID';
2727 // const location = 'global';
2828 // const text = 'text to translate';
2929
30- // [START translate_v3_translate_text_0]
3130 // Imports the Google Cloud Translation library
31+ // [START translate_v3_import_client_library]
3232 const { TranslationServiceClient} = require ( '@google-cloud/translate' ) ;
33- // [END translate_v3_translate_text_0 ]
33+ // [END translate_v3_import_client_library ]
3434
35- // [START translate_v3_translate_text_1]
3635 // Instantiates a client
3736 const translationClient = new TranslationServiceClient ( ) ;
38- // [END translate_v3_translate_text_1]
3937
4038 async function translateText ( ) {
41- // [START translate_v3_translate_text_2]
39+ // MIME type of the content to translate
40+ // Supported MIME types:
41+ // https://cloud.google.com/translate/docs/supported-formats
42+ const mimeType = 'text/plain' ;
43+
4244 // Construct request
4345 const request = {
4446 parent : `projects/${ projectId } /locations/${ location } ` ,
4547 contents : [ text ] ,
46- mimeType : 'text/plain' , // mime types: text/plain, text/html
48+ mimeType : mimeType ,
4749 sourceLanguageCode : 'en' ,
4850 targetLanguageCode : 'sr-Latn' ,
4951 } ;
50- // [END translate_v3_translate_text_2]
5152
52- // [START translate_v3_translate_text_3]
5353 // Run request
5454 const [ response ] = await translationClient . translateText ( request ) ;
5555
5656 for ( const translation of response . translations ) {
5757 console . log ( `Translation: ${ translation . translatedText } ` ) ;
5858 }
59- // [END translate_v3_translate_text_3]
6059 }
6160
6261 translateText ( ) ;
0 commit comments