In this example, I have made a textArea and a submit button. When you will click the submit button, translated text will appear below the button.


Example demo:

Example Code:

function doGet() {

  var app = UiApp.createApplication();


  //create a penel which will hold all the elements

  var panel = app.createVerticalPanel();

  var label1 = app.createLabel('Write the text to translate');


  //Create text area which will hold the source text

  var textArea1 = app.createTextArea().setName('ta1').setWidth('300').setHeight('100');


  //Create a button

  var button = app.createButton('Translate');

  //Create a click handler which will call the translate function

  var handler = app.createServerClickHandler('translate');




  var label2 = app.createLabel('Taranslated text:');

  //Create text area which will hold translated text

  var textArea2 = app.createTextArea().setId('ta2').setWidth('300').setHeight('100');


  //add all the elemnts to the panel



  //Add the panel to the application 


  return app;


function translate(e){

  //Get the current activae application

  var app = UiApp.getActiveApplication();

  //get the source text

  var text = e.parameter.ta1;


  //Now translate the text

  var translatedText = LanguageApp.translate(text, 'en', 'es');


  //set the text of text area 2 as the translated text


  return app;