The problem is not that the Language API isn't responding correctly. It's that 
you're trying to alert res before the API responds. The asynchronous nature of 
the API means that anything that depends on the response needs to be done in 
(or after) the callback. So you could change your code to look like this:

function translate(){
 google.language.translate('house','en','ru',function(result){
  res = result.translation;
  alert(res);
 }
}

translate();

Notice that the alert happens inside the callback, rather than immediately 
after the call to translate().

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
[email protected]

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

On Jun 29, 2010, at 8:38 AM, Alistair wrote:

> I'm trying to make "result.translation" a variable that I can use
> globally but I can't seem to do it. The alert in the following script
> brings back "undefined".
> 
> google.load("language", "1");
> $(document).ready(function(){
>       var res;
>       function translate(){
>               google.language.translate("house","en","ru", function(result){ 
> res =
> result.translation; });
>       }
>       translate();
>       alert(res);
> });
> 
> 
> I'm looking for something like:
> var res = google.language.translate("house","en","ru");
> 
> Could someone please help me make "result.translation" global?
> Thanks.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google AJAX APIs" 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-ajax-search-api?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Google AJAX APIs" 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-ajax-search-api?hl=en.

Reply via email to