After seeing the operation of the Google AJAX APIs I came up with an alternative way to translate Web pages leveraging our real-time prototype.js , you can mark the HTML tags we want to translate, instead of subjecting the entire document to translation. : To mark the HTML tags I used to translate the attribute rel , setting it to translate :
1 |
With a simple function, then we can use prototype.js to process all HTML tags with rel='translate' :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | / ** * @ Name: translate () * @ Description: translate * / function translate () { ) . each ( $ $ ('[Rel = "translate"]'). Each ( e ) { function (s) { ( 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
Of course the script can (and / or must) be completed as appropriate. . It is interesting to note, however, that it is possible to specialize in order to replace the images (in the case of graphical buttons that contain text), or develop him as a special TAG INPUT or TEXTAREA .
One of the limitations that I encountered, and I would like to deepen, the number of characters that can be translated. In case of important texts, in fact, it is not difficult to get an error: that in fact I run the script with an alert() .






Latest Comments
Joseph : Hi I wanted to ask you how you can do in the post I uploaded a gallery of 50 images, for example, ...
Joseph : Council if you want to restore all thumbs plugin Regenerate Thumbnails
Joseph : Thank you! Guide very interesting.
Giovambattista Fazioli : update: WordPress has updated the documentation of this function.
Giovambattista Fazioli : @ iLeW: of course, see here