Hi Daniela --
In order to translate other parts of the page, you need to be able to
grab the text and then set it to the translated text. To grab those
other parts of the page (they are called DOM Elements), you need to be
able to uniquely reference them. Right now, you use
document.getElementById("translation") to grab the translation div,
and then you set it with innerHTML. You need to do the same for your
title and block divs.
Currently those divs do not have ID's, though. You should set them.
In Blooger, go to Settings -> Layout -> Edit HTML. Add two unique
ID's to the divs you wish to translate, aka
id="someuniqueidentifier". Then in your Javascript, grab the
innerHTML of these divs, send it off for translation, and set the
resulting translation to be the text of those divs.
Good luck!
-Ben
On Mar 27, 1:14 am, Quotta <[email protected]> wrote:
> 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("language", "1");
> function simpleTranslation() {
> var text = document.getElementById("text").innerHTML;
> var stringa= (navigator.userLanguage);
> var lang= stringa.substring(0,2);
> if (lang == "en")
> google.language.translate(text, 'it', 'en',
> insertHTML );
> else if (lang == "fr")
> google.language.translate(text, 'it', 'fr',
> insertHTML );
> else if (lang == "es")
> google.language.translate(text, 'it', 'de',
> insertHTML );
> else if (lang == "pt")
> google.language.translate(text, 'it', 'pt',
> insertHTML );
> else if (lang == "ru")
> google.language.translate(text, 'it', 'ru',
> insertHTML );
> else if (lang == "ja")
> google.language.translate(text, 'it', 'ja',
> insertHTML );
> else if (lang == "el")
> google.language.translate(text, 'it', 'el',
> insertHTML );
> else if (lang == "es")
> google.language.translate(text, 'it', 'es',
> insertHTML );
> else if (lang == "nl")
> google.language.translate(text, 'it', 'nl',
> insertHTML );
> else if (lang == "ar")
> google.language.translate(text, 'it', 'ar',
> insertHTML );
> else if (lang == "zh")
> google.language.translate(text, 'it', 'zh',
> insertHTML );
> }
> function insertHTML( result ) {
> if (result.translation) {
> document.getElementById("translation").innerHTML =
> result.translation;
> document.getElementById("text").style.display =
> 'none';
> }
> }
> function TranslateFlag(lang) {
> google.language.translate(document.getElementById
> ("text").innerHTML, "", lang, function(result) {
> if (!result.error) {
> var container = document.getElementById
> ("translation");
> container.innerHTML = result.translation;
> document.getElementById("text").style.display =
> 'none';
> }
> });}
>
> //
> google.setOnLoadCallback( simpleTranslation );
> </script>
>
> - search <p><data:post.body/></p> and replace with
> <b:if cond='data:blog.pageType == "item"'>
> <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 == "item"'>
> <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
-~----------~----~----~----~------~----~------~--~---