Hi! I'm Daniela... and sorry for my English... ;)
I was looking for an automatic and free translator for my italian blog
(s) when I found Google API Language, so I tried to create it. This
translator can detect the language of the browser and automatically
replace the text with the user's language. I use this function only in
the single page of a post to amend at the limited number of characters
that can be translate at one time. I'm not a Javascript geek ;) but I
mean that can be useful (and the flags are so pretty!).
Someone would help me to improve this script?
- I can't understand how to translate the post title, too.
- ... how don't translate the blockquote, or other defined tag.
- ... translate, at least, the first part of post with a large number
of characters

You can see an example in this post (http://egoplayground.blogspot.com/
2009/03/il-form-dei-commenti-sotto-al-post.html) and this is the code:

- To insert after <head>:
<script src='http://www.google.com/jsapi' type='text/javascript'/>
  <script type='text/javascript'>
 google.load(&quot;language&quot;, &quot;1&quot;);
   function simpleTranslation() {
   var text = document.getElementById(&quot;text&quot;).innerHTML;
   var stringa= (navigator.userLanguage);
       var lang= stringa.substring(0,2);
   if (lang == &quot;en&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;en&#39;,
insertHTML );
   else if (lang == &quot;fr&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;fr&#39;,
insertHTML );
   else if (lang == &quot;es&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;de&#39;,
insertHTML );
   else if (lang == &quot;pt&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;pt&#39;,
insertHTML );
      else if (lang == &quot;ru&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;ru&#39;,
insertHTML );
      else if (lang == &quot;ja&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;ja&#39;,
insertHTML );
      else if (lang == &quot;el&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;el&#39;,
insertHTML );
      else if (lang == &quot;es&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;es&#39;,
insertHTML );
      else if (lang == &quot;nl&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;nl&#39;,
insertHTML );
      else if (lang == &quot;ar&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;ar&#39;,
insertHTML );
      else if (lang == &quot;zh&quot;)
   google.language.translate(text, &#39;it&#39;, &#39;zh&#39;,
insertHTML );
 }
 function insertHTML( result ) {
   if (result.translation) {
   document.getElementById(&quot;translation&quot;).innerHTML =
result.translation;
   document.getElementById(&quot;text&quot;).style.display =
&#39;none&#39;;
   }
 }
function TranslateFlag(lang) {
 google.language.translate(document.getElementById
(&quot;text&quot;).innerHTML, &quot;&quot;, lang, function(result) {
        if (!result.error) {
            var container = document.getElementById
(&quot;translation&quot;);
            container.innerHTML = result.translation;
             document.getElementById(&quot;text&quot;).style.display =
&#39;none&#39;;
        }
    });
}
//
 google.setOnLoadCallback( simpleTranslation );
 </script>

- search <p><data:post.body/></p> and replace with
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<div id='translation'/>
</b:if>
<div id='text'><p><data:post.body/></p></div>

- for the flag search <div class='post'> and paste
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<div class='flag'>
<a href="javascript:TranslateFlag('en')">
<img src="http://quottaego.googlepages.com/en.gif"; title="English"></
a>
<a href="javascript:TranslateFlag('fr')">
<img src="http://quottaego.googlepages.com/fr.jpg"; title="French"></a>
<a href="javascript:TranslateFlag('de')">
<img src="http://quottaego.googlepages.com/de.jpg"; title="German"></a>
<a href="javascript:TranslateFlag('pt-PT')">
<img src="http://quottaego.googlepages.com/pt.jpg";
title="Portuguese"></a>
<a href="javascript:TranslateFlag('ru')">
<img src="http://quottaego.googlepages.com/ru.gif"; title="Russian"></
a>
</div>
  </b:if>

Thanx a lot
Daniela

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