My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Saturday, March 03, 2007

DOM Google Translator

Hi guys :-)
I've just uploaded my last function on devpro that's compatible with most common browser.
It's based on DOM and creates automatically translation request url to view a selected text or an entire page inside wonderful Google Translator free service page.

Its usage is really simple:

onload = function(){
document.body.appendChild(
GoogleTranslator()
);
};

With these example You'll append at the end of document.body a select with LANG - TRANSLATION values and a link.

Returned div has exactly these two elements and You could customize them using your own CSS.

Here You can view another example

<style type="text/css">
#mytranslator {
font-size: 8pt;
font-family: Verdana, Helvetica, sans-serif;
border: 1px solid silver;
padding: 4px;
background-color: #F5F5F5;
color: #000;
width: 160px;
}
#mytranslator select {
font-size: 8pt;
}
#mytranslator a {
display: block;
color: #00F;
text-decoration: none;
border-bottom: 1px dotted black;
}
</style>
<script type="text/javascript">
onload = function(){
var translator = GoogleTranslator(
"Translate",
"es",
"ENG - ESP"
);
document.getElementById("mytranslator").appendChild(translator);
};
</script>

In this way You'll create a translator shortcut with default English to Espanol translation.

You can view an example, using English to Italian as default, on the right content of this page, do You like it? :-)

6 comments:

Andrea Giammarchi said...

Bruno please write comments about choosed post ... however, APC and YUI aren't a solution for PHP upload progress bar.
You're probably a bit confused about client/server interaction and You should look for PECL package to write something about upload client/server interaction (or study my old pure PHP solution).

kentaromiura said...

http://mykenta.blogspot.com/2007/03/google-dom-translator-scriptlet.html

Andrea Giammarchi said...

thank you kentaromiura but it seems that Your link doesn't work on my FireFox. Could You test them?

kentaromiura said...

range, i m at home now and i tested on ff 2.002 and it works,
it works in 1.5x and IE 7,
i didn't test other browser but it should work,
be aware that even if I ve an error in my blog (i must correct it later) the scriplet work, what error give you?

Andrea Giammarchi said...

Ooops, sorry kentaromiura, I didn't understand what does your link (append my combo at the end of generic page).

It works perfectly, thank You :-)

Internet-Marketing said...

Hello,

This is a very good article.


Suchmaschineneintrag
Besuchertausch
Newsletterwerbung an ├╝ber 82.000 User
Versicherungsvergleich
Handyshop
Handy-Angebote