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

HTML:
  1. "translate" > Questo testo deve essere tradotto </p> <p "translate" rel => This text should be translated </ p>

With a simple function, then we can use Prototype.js to process all the HTML tags with rel='translate'

JavaScript:
  1. / **
  2. * @ Name: translate ()
  3. * @ Description: translate
  4. * /
  5. function translate () (
  6. ) . each ( $ $ ( '[Rel = "translate"]'). Each (
  7. e ) { function (e) (
  8. ( e. innerHTML , 'it' , 'en' , google. language. translate (e. innerHTML, 'en', 'en',
  9. result ) { function (result) (
  10. result. translation ) { if (result. translation) (
  11. result. translation ; e. innerHTML = result. Translation;
  12. { ) Else (
  13. 'Translate Error! \n \n ' + result. error . message ) ; alert ( 'Error Translate \ n \ n' + result. error. message);
  14. )
  15. )
  16. )
  17. )
  18. )
  19. )

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()

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

There are no comments for this post

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL