使用Google翻译时,有没有办法翻译从用户表单输入生成的内容(使用我在下面使用的方法)?
现在,页面将翻译,但是当用户填写并在翻译页面上提交表单时,答案当然是以英语返回的。这是有道理的,因为翻译发生在表单提交之前(并且发生在Google的服务器上)。
有没有相对简单的方法?我仍然对javascript有所了解,所以您可以提供的任何细节都非常感谢。只是想到这个让我的小脑袋爆炸了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!-- Begin CE MP Savings Calc script
function doMath3() {
var one = parseInt(document.theForm3.elements[0].value);
var two = parseInt(document.theForm3.elements[1].value);
var three = one * two;
var z4yearlyCash = three * 4.25 * 12;
var z3yearlyCash = three * 3.75 * 12;
var z2yearlyCash = three * 3 * 12;
var z1yearlyCash = three * 2.5 * 12;
var baseyearlyCash = three * 1.5 * 12;
var selection = document.getElementsByName("zone")[0].value;
var answerCemp = document.getElementById("answerCemp");
if (document.theForm3.elements[0].value == ""){
alert("Please enter the number of days a month you commute on Commuter Express.")
}
if (document.theForm3.elements[1].value == ""){
alert("Please enter the number of times you board a Commuter Express daily.")
}
if(one > 31){
alert("Come now, no month has " + one + " days! Please try again.");
}
else if(selection == "z4"){
var prodZ4 = z4yearlyCash - 1680;
if(prodZ4 > 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Yearly Savings<\/h3><p>If you pay cash, your yearly expense is $" + z4yearlyCash + ".<br>Commuter Express Zone 4 Monthly Passes cost $1680 per year.<br><strong>That's a yearly savings of $" + prodZ4 + "!<\/strong><br><strong><a href='http://store.ladottransit.com/Merchant2/merchant.mvc?Screen=CTGY&Store_Code=LTSO&Category_Code=MP4'>Buy a Commuter Express Zone 4 Monthly Pass now.<\/a><\/strong><\/p><\/div>";
}
else if(prodZ4 <= 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Results<\/h3><p>Looks like you don't ride Commuter Express often enough to benefit from purchasing a Monthly Pass. Trip Tickets may be a better option for you. <strong><a href='#triptickets'>Try the Trip Tickets Calculator below.<\/a><\/strong><\/p><\/div>";
}
}
else if(selection == "z3"){
var prodZ3 = z3yearlyCash - 1488;
if(prodZ3 > 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Yearly Savings<\/h3><p>If you pay cash, your yearly expense is $" + z3yearlyCash + ".<br>Commuter Express Zone 3 Monthly Passes cost $1488 per year.<br><strong>That's a yearly savings of $" + prodZ3 + "!<\/strong><br><strong><a href='http://store.ladottransit.com/Merchant2/merchant.mvc?Screen=PROD&Store_Code=LTSO&Product_Code=LADOTMPZ3&Category_Code=MP4'>Buy A Commuter Express Zone 3 Monthly Pass Now<\/a><\/strong><\/p><\/div>";
}
else if(prodZ3 <= 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Results<\/h3><p>Looks like you don't ride Commuter Express often enough to benefit from purchasing a Monthly Pass. Trip Tickets may be a better option for you. <strong><a href='#triptickets'>Try the Trip Tickets Calculator below.<\/a><\/strong><\/p><\/div>";
}
}
else if(selection == "z2"){
var prodZ2 = z2yearlyCash - 1200;
if(prodZ2 > 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Yearly Savings<\/h3><p>If you pay cash, your yearly expense is $" + z2yearlyCash + ".<br>Commuter Express Zone 2 Monthly Passes cost $1200 per year.<br><strong>That's a a yearly savings of $" + prodZ2 + "<\/strong>!<br><strong><a href='http://store.ladottransit.com/Merchant2/merchant.mvc?Screen=PROD&Store_Code=LTSO&Product_Code=LADOTMPZ2&Category_Code=MP4'>Buy A Commuter Express Zone 2 Monthly Pass Now<\/a><\/strong><\/p><\/div>";
}
else if(prodZ2 <= 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Results<\/h3><p>Looks like you don't ride Commuter Express often enough to benefit from purchasing a Monthly Pass. Trip Tickets may be a better option for you. <strong><a href='#triptickets'>Try the Trip Tickets Calculator below.<\/a><\/strong><\/p><\/div>";
}
}
else if(selection == "z1"){
var prodZ1 = z1yearlyCash - 960;
if(prodZ1 > 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Yearly Savings<\/h3><p>If you pay cash, your yearly expense is $" + z1yearlyCash + ".<Br>Commuter Express Zone 1 Monthly Passes cost $960 per year.<br><strong>That's a yearly savings of $" + prodZ1 + "<\/strong>!<br><strong><a href='http://store.ladottransit.com/Merchant2/merchant.mvc?Screen=PROD&Store_Code=LTSO&Product_Code=LADOTMPZ1&Category_Code=MP4'>Buy A Commuter Express Zone 1 Monthly Pass Now<\/a><\/strong><\/p><\/div>";
}
else if(prodZ1 <= 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Results<\/h3><p>Looks like you don't ride Commuter Express often enough to benefit from purchasing a Monthly Pass. Trip Tickets may be a better option for you. <strong><a href='#triptickets'>Try the Trip Tickets Calculator below.<\/a><\/strong><\/p><\/div>";
}
}
else if(selection == "Base"){
var prodBase = baseyearlyCash - 684;
if(prodBase > 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Yearly Savings<\/h3><p>If you pay cash, your yearly expense is $" + baseyearlyCash + ".<br>Commuter Express Base Monthly Passes cost $684 per year.<br><strong>That's a yearly savings of $" + prodBase + "!<\/strong><br><strong><a href='http://store.ladottransit.com/Merchant2/merchant.mvc?Screen=PROD&Store_Code=LTSO&Product_Code=LADOTMPB&Category_Code=MP4'>Buy A Commuter Express Base Monthly Pass Now<\/a><\/strong><\/p><\/div>";
}
else if(prodBase <= 0){
answerCemp.innerHTML="<div class='answerbox'><h3>Your Results<\/h3><p>Looks like you don't ride Commuter Express often enough to benefit from purchasing a Monthly Pass. Trip Tickets may be a better option for you. <strong><a href='#triptickets'>Try the Trip Tickets Calculator below.<\/a><\/strong><\/p><\/div>";
}
}
}
// End CE MP Savings Calc script -->
</script>
</head>
<body>
<form action="javascript:window.location = 'http://translate.google.com/translate?hl=en&sl=en&tl=' + document.translateform.translate.value + '&u=' + window.location.href;" method="get" name="translateform">
<label for="translate">translate this page</label>
<select name="translate" id="translate">
<option value="es">Spanish</option>
<option value="ar">Arabic</option>
<option value="zh-CN">Chinese Simplified</option>
<option value="zh-TW">Chinese Traditional</option>
<option value="nl">Dutch</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="el">Greek</option>
<option value="it">Italian</option>
<option value="ja">Japanese</option>
<option value="ko">Korean</option>
<option value="pt">Portuguese</option>
<option value="ru">Russian</option>
</select>
<div class="gobuttonwrapper">
<input name="submit" type="submit" value="go" class="gobutton">
</div>
</form>
<div class="calcform">
<form name="theForm3">
<h2><a name="cemp" id="cemp"></a>You Do the Math: Commuter Express Monthly Pass Vs. Cash</h2>
<div class="calcform-content">
<div class="formrow-calc">
<div class="calcform-col1">
<label for="trips-cemp">Daily boardings on Commuter Express Bus*:</label>
<input type="text" id="trips-cemp">
</div><div class="calcform-col3"></div>
</div>
<div class="formrow-calc">
<div class="calcform-col1">
<label for="days-cemp">Days you ride Commuter Express <strong>per month</strong>:</label>
<input type="text" id="days-cemp"></div>
</div>
<div class="formrow-calc">
<div class="calcform-col1">
<label for="choosezone">Choose Zone:</label>
<select name="zone" id="choosezone">
<option value="Base">Base</option>
<option value="z1">Zone 1</option>
<option value="z2">Zone 2</option>
<option value="z3">Zone 3</option>
<option value="z4">Zone 4</option>
</select>
</div>
</div>
<div class="clear"></div>
<div align="center">
<button type="submit" onclick="doMath3(); return false;" class="btn-submit"><img src="img/btn_savings.png" alt="Show My Yearly Savings"><br>
<img src="img/arrow_results.png" alt="your results will display below"></button>
</div>
</div>
</form>
<div id="answerCemp"></div>
</div>
</body>
</html>
答案 0 :(得分:0)
如果您自己创建页面,特别是在要翻译页面的各个元素的位置,则可以使用此插件。要填充翻译数据,您可以使用Google翻译来获取文字短语的翻译版本。
https://github.com/coolbloke1324/jquery-lang-js
该插件跨页面具有语言持久性,允许短语和基于正则表达式的匹配,可以处理任意数量的语言选项,并允许您触发所描述的点击事件的更改。
您可以在https://www.orbzu.com上看到它被实时使用(查看页面左上方的标志图标,然后选择一种新语言以查看页面上的文字自动更改。)