Next: A small google translator

A small google translator

This example show how to use the textArea and retrieve the content when I submit the value.


1:    function doGet() {  
2:     var app = UiApp.createApplication();  
3:     //create a penel which will hold all the elements  
4:     var panel = app.createVerticalPanel();  
5:     var label1 = app.createLabel('Write the text to translate');  
6:     //Create text area which will hold the source text  
7:     var textArea1 = app.createTextArea().setId('originText').setName('originText').setWidth('300').setHeight('100');     
8:     textArea1.setText('Roma è la capitale d\'Italia');  
9:     //Create a button  
10:     var button = app.createButton('Translate');  
11:     var label2 = app.createLabel('Taranslated text:');  
12:     //Create text area which will hold translated text  
13:     var textArea2 = app.createTextArea().setId('destitinationText').setWidth('300').setHeight('100');        
14:     //Create a click handler which will call the translate function  
15:     var handler = app.createServerClickHandler('translate');  
16:     handler.addCallbackElement(textArea1); // This row is important  
17:     button.addClickHandler(handler);     
18:     //add all the elemnts to the panel  
19:     panel.add(label1).add(textArea1).add(button).add(label2).add(textArea2);     
20:     //Add the panel to the application   
21:     app.add(panel);   
22:     return app;  
23:    }  
24:    function translate(e){  
25:     //Get the current activae application  
26:     var app = UiApp.getActiveApplication();  
27:     //get the source text of TextArea1     
28:     var text = e.parameter.originText;  
29:     //Now translate the text  
30:     var translatedText = LanguageApp.translate(text, 'it', 'en');  
31:     //set the text of text area 2 as the translated text  
32:     app.getElementById('destitinationText').setText(translatedText);  
33:     return app;  
34:    }