开发者

Encoding GBK2312 Condundrum

I am an amateur coder and I have a small problem.

My goal is to have one text input with two buttons.

  • The first button uses a bit of Javascript called SundayMorning to translate the text (to Chinese)
  • The second button submits the text to a URL. The URl requires that Chinese text be encoded it in GBK2312 character set.

I have duct taped together various found code to the result I have now. Due to the finicky behavior of the SundayMorning Javascript, my solution is to have two input boxes, the second of which I will hide.

Right now, this doesn't work:

  • I am unable to encode the Chinese in GBK2312, no matter what I try.
  • BONUS CONUNDRUM: The second box copies my input letter by letter as I type, but does not copy the Chinese translation that the Javascript returns.

Sorry for my janky amateur code. I defer to those more clever, if you have any kind suggestions.

<head>   
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> 
<script type='text/javascript' Src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'> 
</script> 

///THIS JS TRANSLATES THE TEXT INLINE  
<script
     type="text/javascript"
     src="jquery.sundaymorning.js"> 
</script> 
<script type="text/javascript"> 
    $(function() {
            $('#example3').sundayMorningReset();
        $('#example3 input[type=image]').click(function(evt) {
            $.sundayMorning(
                $('#example3 input[type=text]').val(),{source:'en', destination:'ZH', menuLeft:evt.pageX, menuTop:evt.pageY},function(response) {$('#example3 input[type=text]').val(response.translation);});});});
        </script> 
///

///THIS PUTS THE CONTENT OF THE TRANSLATION BOX INTO THE SUBMISSION BOX 
<script type="text/javascript"> 
$(document).ready(function(){
var $url = $("#url");
$("#track").keyup(function() {
    $url.val(this.value);});
$("#track").blur(function() {
    $url.val(this.value);});});
</script> 

///THIS PUTS THE CONTENT OF THE SUBMISSION INSIDE A URL 
<SCRIPT type="text/javascript"> 
function goToPage(url)
{
var initial = "http://example.com/";
var extension = ".html";  
document.something.action=initial+url+extension;
}
</SCRIPT> 

</head> 
<body> 

<div id="featured"> 
<div id="example3"> 
        <input type="text" name="track" id="track" value="" class="box"onkeydown="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('mama').click();}};"/> 
        <input type="image" src="http://taobaofieldguide.com/images/orange-translate-button.png" id="searchsubmit" value="Translate" class="btn" /> 
</div> 

<FORM name="something" method="post" onsubmit="goToPage(this.url.value);"> 
<input type="text" id="url";>开发者_如何学编程; 
<INPUT type="submit" id="mama" value="GO"  > 
</FORM>    
</div> 

</body> 


The jQuery plugin looks like it is using an old version of the Google Translate API.

On SundayMorning website (http://sundaymorning.jaysalvat.com/), get this error message:

Translation error: Please use Translate v2. See http://code.google.com/apis/language/translate/overview.html

You probably need to sign up for an Translate API key and update code to use Google Translate v2 instead of v1, or find a new library which works "out of the box".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜