You need to access injected scripts through the $wnd variable (http://
code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-
toolkit-doc-1-5&t=DevGuideJavaScriptFromJava) - maybe
$wnd.google.language.translate(text, from, to, function(result) would
work for you.

//Adam

On 29 Mar, 23:23, Persuader <[email protected]> wrote:
> Hello!
>
> I try to write a wrapper for google ajax language api.
>
> I'd like to develope the equivalent of this HTML in gwt
>
>  <head>
>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/
>
>     <title>Google AJAX Language API - Basic Translation</title>
>     <script type="text/javascript" src="http://www.google.com/jsapi";></
> script>
>
>      <script type="text/javascript">
>     function translate(text, from, to, output){
>
>         google.language.translate(text, from, to, function(result) {
>         if (!result.error) {
>           output.innerHTML = result.translation;
>          }
>       });
>
>       return akarmi;
>     }
>
>     function a() {
>      alert(translate("snow","en","hu", document.getElementById
> ("translation")));
>      }
>
>       function loadgoogle() {
>         google.load('language', '1');
>      }
>
>       </script>
>   </head>
>
>   <body>
>   <script type="text/javascript">
>     loadgoogle();
>   </script>
>
>   <input name="firstbutton" type="button"  onclick="a()" value="This
> is not disabled" />
>     <div id="translation"></div>
>
> This one worked fine. To do the same in gwt (with textBox input of the
> text to translate) I tried it this way :
>
> in class which implements entrypoint :
>
> public void onModuleLoad() {
>                  TranslateBox translateBox = new TranslateBox(
>                                  "input",
>                                  new TextBox(),
>                                  "answer",
>                                  new Label()
>                                 );
>                  RootPanel.get().add(translateBox);
>         }
>
> the translatebox class looks like this:
>
> public class TranslateBox extends Composite {
>         private TextBox inputTextBox;
>         private Label answerBox;
>         public static final String FROM = "en";
>         public static final String TO = "hu";
>
>         public TranslateBox(String inputLabel,final TextBox inputTextBox,
> String answerLabel, final Label answerBox) {
>                 super();
>
>                 this.inputTextBox = inputTextBox;
>                 this.answerBox = answerBox;
>                 Grid grid = new Grid(5,1);
>                 initWidget(grid);
>
>                 grid.setWidget(0, 0, new Label(inputLabel));
>                 grid.setWidget(1, 0, inputTextBox);
>                 grid.setWidget(2, 0, new Label(answerLabel));
>                 grid.setWidget(3, 0, answerBox);
>                 Button searchButton = new Button("search");
>                 searchButton.addClickListener(new ClickListener(){
>
>                         public void onClick(Widget sender) {
>                                 init();
>                                 translate(
>                                                 inputTextBox.getText(),
>                                                 FROM,
>                                                 TO,
>                                                 answerBox);
>                         }});
>
>                 grid.setWidget(4, 0, searchButton);
>         }
>
>         public static native void init()
>          /*-{
>              google.load('language', '1');
>          }-*/;
>
>         public static native String translate(
>                         String text,
>                         String from,
>                         String to,
>                         Label answerbox)
>          /*-{
>              google.language.translate(text, from, to, function(result) {
>         if (!result.error) {
>           [email protected]::setText
> (Ljava/lang/String;)(result.translation);
>         }
>       });
>          }-*/;
>
> }
>
> I tried to inject the JS file for language api with the html file:
>
>     <script type="text/javascript" src="http://www.google.com/jsapi";></
> script>
>
> I tried it before or after the injection of the nocache js and I tried
> it
> with the line
>
>   <script src="http://www.google.com/jsapi";></script>
>
> adding just before the closing   </module> tag.
> But it doesn't matter which way I tried it gives the exeption:
>
> com.google.gwt.core.client.JavaScriptException: (TypeError): 'google'
> is undefined.
>
> Could somebody please help what's wrong with my code?
> what's the right way to inject external JS files?
>
> thanks:
> -P
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to