Translate
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.
References:
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');
handler.addCallbackElement(panel);
button.addClickHandler(handler);
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
app.add(label1).add(textArea1).add(button).add(label2).add(textArea2);
//Add the panel to the application
app.add(panel);
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
app.getElementById('ta2').setText(translatedText);
return app;
}