Google AJAX Language API and Prototype.js
Tuesday, May 13, 2008 After seeing the operation of the Google AJAX API I was reminded of an alternative way to translate our web pages exploiting realtime Prototype.js you can mark the HTML tags you want to translate, instead of having the entire document for translation. To mark the HTML tags I used to translate the attribute rel setting it to translate
With a simple function, then we can use Prototype.js to process all the HTML tags with rel='translate'
- / **
- * @ Name: translate ()
- * @ Description: translate
- * /
- function translate () (
- ) . each ( $ $ ( '[Rel = "translate"]'). Each (
- e ) { function (e) (
- ( e. innerHTML , 'it' , 'en' , google. language. translate (e. innerHTML, 'en', 'en',
- result ) { function (result) (
- result. translation ) { if (result. translation) (
- result. translation ; e. innerHTML = result. Translation;
- { ) Else (
- 'Translate Error! \n \n ' + result. error . message ) ; alert ( 'Error Translate \ n \ n' + result. error. message);
- )
- )
- )
- )
- )
- )
You can see this in action on e-lementi.com
Obviously, the script can (and / or must) be completed as appropriate. Interestingly, however, which can be so specialized as to replace the images (in the case of graphical buttons that contain text) or have elaborate details such as TAG INPUT or TEXTAREA
One of the limitations I faced, and would like to expand, the number of characters that can be translated. In case of important texts, in fact, it is difficult to get an error: that in fact I managed in the script with an alert()













There are no comments for this post
Leave a comment