homepage Welcome to WebmasterWorld Guest from 54.161.228.29
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Inline Language Translation with Google AJAX API Problem
script33




msg:3740407
 12:46 pm on Sep 8, 2008 (gmt 0)

<head>
<script type="text/javascript"
src="http://www.google.com/jsapi"></script>
<script type="text/javascript">

// Initialize version 1.0 of Google AJAX API
google.load("language", "1");

function translate(lang) {
var source = document.getElementById("article").innerHTML;
var len = content.length;

// Google Language API accepts 500 characters per request
var words = 500;

// This is for English pages, you can change the
// sourcelang variable for other languages
var sourcelang = "en";
document.getElementById("translation").innerHTML = "";

for(i=0; i<=(len/words); i++) {
google.language.translate (source.substr(i*words, words),
"en", lang, function (result) {
if (!result.error) {
document.getElementById("translation").innerHTML
= document.getElementById("translation").innerHTML
+ result.translation;
} }); }

// Hide the text written in the original language
document.getElementById("article").style.display = 'none';
return false;
}

// Switch to the original language

function original() {
document.getElementById("translation").style.display='none';
document.getElementById("article").style.display = 'block';
return false;
}
</script>
</head>
<body>
<select onchange="translate(this.options[this.selectedIndex].value);">
<option value="de">deutsch</option>
<option value="pt">português</option>
<option value="fr">français</option>
<option value="ja">&#26085;&#26412;&#35486;</option>
<option value="ar">&#1593;&#1614;&#1585;&#1614;&#1576;&#1610;&#1618;</option>
<option value="it">italiano</option>
<option value="ru">p&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;</option>
<option value="po">polski</option>
<option value="zh-CN">&#20013;&#25991;</option>
<option value="es">español</option>
<option value="ko">&#54620;&#44397;&#50612;</option>
<option value="nl">nederlands</option>
<option value="hi">&#2361;&#2367;&#2344;&#2381;&#2342;&#2368; </option>
<option value="el">&#917;&#955;&#955;&#951;&#957;&#953;&#954;&#942;</option>
<option value="ro">român&#259;</option>
</select>
</body>

this is a drop down menu for translation
But i want <a> herf links for this work
how i can do it?

this code don't work:
<a href="#" onclick="translate(this.options[this.selectedIndex].value);">germany</a>

please help ....

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved