Saturday, March 3, 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? :-)

No comments:

Post a Comment