Wow! what a fast response, thanks. I will give your suggestion a try
now. This is so exciting if I can get this to work! :-)

On Mar 10, 10:39 am, Jeremy Geerdes <[email protected]> wrote:
> How you would do this will depend very much on the nature of your  
> page, the number of fields you're wanting to translate, and a number  
> of other factors. The simplest way, of course, would be to loop  
> through the fields you want to translate, generating what's called a  
> function closure for each one so that it will be able to find itself  
> back when the translation returns.  For instance:
>
> var fields=document.getElementsByTagName('input');
> var srcLang=''; // leave blank to auto-detect
> var desLang='en'; // change to whatever you want it to go to
>
> var myClosure=function(field){ // here is the closure, a function that  
> returns a function
>   return function(response){
>    if(!response.error){
>     field.value=response.translation
>    }
>   }
>
> }
>
> for(var i=0;i<fields.length;i++){
>
> google
> .language
> .translate(fields[i].value,srcLang,desLang,myClosure(fields[i]));
>
> }
>
> If there is a large number of small fields, though, it may be better  
> performance-wise to combine them into groups that are separated out by  
> xml or some other markup that your script will be able to parse out  
> when the translation returns.  The key here will be that, when using  
> the JSAPI, you will be using the GET method, and Google limits URL  
> lengths - which is how parameters are passed with the GET method - to  
> no more than 2,000 characters, including encoded characters and such.
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project 
> quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://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, 
> athttp://jgeerdes.blogspot.com
>   !
>
> On Mar 10, 2009, at 5:13 AM, Reggie wrote:
>
>
>
> > hi all, loving the language api. I am having a problem figuring out
> > how I can dynamically translate all text fields on a web page when the
> > page loads, can anyone help?
--~--~---------~--~----~------------~-------~--~----~
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