GBK2312 编码难题

发布于 2024-11-14 13:29:44 字数 2568 浏览 1 评论 0 原文

我是一名业余编码员,我有一个小问题。

我的目标是使用两个按钮进行一个文本输入。

  • 第一个按钮使用了一些 Javascript 调用 SundayMorning 来 将文本翻译成中文
  • 第二个按钮将文本提交给 网址。 URl要求中文 文本编码为GBK2312 字符集。

我已经用管道将各种找到的代码粘贴到了我现在的结果中。由于 SundayMorning Javascript 的挑剔行为,我的解决方案是有两个输入框,我将隐藏第二个输入框。

现在,这不起作用:

  • 无论我如何尝试,我都无法将中文编码为 GBK2312。
  • 额外难题:第二个框在我键入时逐个字母地复制我输入的内容,但不复制 Javascript 返回的中文翻译。

抱歉我的业余代码很糟糕。如果您有任何好的建议,我会尊重那些更聪明的人。

<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> 

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> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请止步禁区 2024-11-21 13:29:44

jQuery 插件看起来使用的是旧版本的 Google Translate API。

在 SundayMorning 网站 (http://sundaymorning.jaysalvat.com/) 上,收到此错误消息:

翻译错误:请使用翻译 v2。请参阅 http://code.google.com/apis/language/translate/overview。 html

您可能需要注册翻译 API 密钥并更新代码才能使用 Google 翻译 v2 而不是 v1,或者找到一个“开箱即用”的新库。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文