Google Apps Script

Class LanguageApp

The Language service provides scripts a way to compute automatic translations of text.

 
// The code below will write "Esta es una prueba" to the log.
 var spanish = LanguageApp.translate('This is a test', 'en', 'es');
 Logger.log(spanish);
 

Methods

MethodReturn typeBrief description
translate(text, sourceLanguage, targetLanguage)StringAutomatically translates some text from a source language to a destination language.
translate(text, sourceLanguage, targetLanguage, advancedArgs)StringAutomatically translates some text from a source language to a destination language.

Detailed documentation

translate(text, sourceLanguage, targetLanguage)

Automatically translates some text from a source language to a destination language.

 
// The code below will write "Esta es una prueba" to the log.
   var spanish = LanguageApp.translate('This is a test', 'en', 'es');
   Logger.log(spanish);
 
A list of language codes is available here.

Parameters

NameTypeDescription
textStringthe text to translate
sourceLanguageStringthe language code in which text is written. If it is set to the empty string, the source language code will be auto-detected
targetLanguageStringthe language code to which the text should be translated

Return

String — the translated text


translate(text, sourceLanguage, targetLanguage, advancedArgs)

Automatically translates some text from a source language to a destination language.

 
// The code below will write "Esta es una <strong>prueba</strong>" to the log.
   var spanish = LanguageApp.translate('This is a &lt;strong&gt;test&lt;/strong&gt;',
                                       'en', 'es', {contentType: 'html'});
   Logger.log(spanish);
 
A list of language codes is available here.

Parameters

NameTypeDescription
textStringthe text to translate
sourceLanguageStringthe language code in which text is written. If it is set to the empty string, the source language code will be auto-detected
targetLanguageStringthe language code to which the text should be translated
advancedArgsObjectoptional JavaScript object fields

Advanced parameters

NameTypeDescription
contentTypeStringthe content type of the text; supported values are 'text' (default) and 'html'

Return

String — the translated text

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.