The problem with your code is that the translation functionality is  
running asynchronously.  Think of it like two monkeys climbing  
together in a tree, and the first monkey jumps over to another tree.   
In synchronous programming, the second monkey sits there and waits  
until the first monkey comes back, and then they continue climbing  
together.  In asynchronous programming, though, the second monkey  
realizes that it could be a bit before the first monkey gets back, so  
it just keeps climbing on its own for a little while until the first  
monkey jumps back from the other tree and the two can resume climbing  
together.

In your code, you expect the callback function that you provide to the  
google.language.translate method to return immediately, so you're  
trying to sit there and wait for it.  But the browser can't wait, so  
it drags your script along and keeps moving.  Thus, the translation  
hasn't been returned, the callback isn't called, and the alert has  
nothing to alert.

The solution is to put the alert and any other work that needs to be  
done with the translation result in the callback method you provide to  
google.language.translate.

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

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

Unless otherwise noted, any price quotes contained within this  
communication are given in US dollars.

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

And check out my blog, Adventures in Web Development, at 
http://jgeerdes.blogspot.com 
  !


On Feb 18, 2009, at 3:26 AM, bertlab wrote:

>
> Hi All,
>
> maybe my problem is related.
> I tried to integrate google translate functionality in my webpage.
>
> ------------------------------------------------------------------------------------
> caller function:
>
> alert(callGoogle('book'));
>
> or:
>
> alert(String(callGoogle('book')));
>
> ------------------------------------------------------------------------------------
> request function:
>
> function callGoogle(translationString){ google.language.translate
> (translationString, "en", "vi", function(result) {
> if (!result.error) {
> //google.language.ContentType='text';
> alert('deep '+ result.translation);
> //return String(result.translation);
> return result.translation;
> } else {
> //alert('Key "' + langKey + '" is not defined!');
> return 'koeln4711';
> };
> });
> };
>
> The "alert" works fine. I think It's a syntax problem with the
> "function(result)". But I definitly need the result value direct from
> the function to get it dynamicly written in my application (alert
> makes no sence for me!).
>
>
> On 11 Feb., 12:59, Ozberk <[email protected]> wrote:
>> Hello Jamie
>>
>> Try this:
>>
>> {
>> 'callback': function () {myFunction(term, region);}
>>
>> }
>>
>> Cheers,
>> Ozberk
>>
>> On Feb 11, 4:32 am, js <[email protected]> wrote:
>>
>>> Hi All
>>
>>> Can anyone please tell me how to pass parameters to callback  
>>> functions
>>> when using the dynamic loading method?
>>
>>> I've read up onhttp://code.google.com/apis/ajax/documentation/#Dynamic 
>>> ,
>>> searched a few places but can't find an answer.  Note that I'm using
>>> the "search" api (with gsc-search-box not displayed), not the
>>> "maps" (as per the example).  The parameters I want to pass are the
>>> 'search term' and the users 'region'.
>>
>>> I'm assuming it's not possible to send parameters to the callbacks,
>>> and that I'll have to either setup global vars, or read values from
>>> hidden input boxes?
>>
>>> Any help/guidance would be appreciated.
>>
>>> Thank you in advance.
>>
>>> Jamie
>
> >


--~--~---------~--~----~------------~-------~--~----~
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