Google翻译工具不适用于输入类型的文本值吗? [英] Google Translate Tool does not work on the input type text value?

查看:88
本文介绍了Google翻译工具不适用于输入类型的文本值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的页面上使用网站的Google翻译工具,它工作正常,但是当我在带有表单的页面上检查该工具时,它并没有更改输入字段中写入的值.

I am using Google Translate tool for website on my page, and it is working fine but when I checked the same on a page with form, it is not changing the value written inside the input field.

我遗漏了某些东西还是Google翻译工具没有做到这一点?

Am I missing something or Google Translate tool does not do it?

PFB是我的测试摘要:

PFB the snippet of my test :

<!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>
<title>Untitled Page</title>
</head>
<body>
<div id="google_translate_element"></div><script>
                                         function googleTranslateElementInit() {
                                             new google.translate.TranslateElement({
                                                 pageLanguage: 'en',
                                                 autoDisplay: false,
                                                 layout: google.translate.TranslateElement.InlineLayout.SIMPLE
                                             }, 'google_translate_element');
                                         }
</script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<form>
<input type="text" value="system" />

<select>
<option value="welcome">Welcome</option>
</select>
<input type="radio" />Right?
<input type="submit" value="Submit" />
</form>
</body>
</html>

推荐答案

很明显,即使在HTML源中进行设置,Google网站翻译器也不会翻译input元素值.我也用textarea元素进行了测试,结果相同.但是,它通过表单字段以外的其他元素来执行翻译;可以使用contenteditable属性创建此类元素,该属性在现代浏览器中得到了广泛支持(尽管不是很普遍) /a>.但是,为了使翻译后的文本与表单一起提交,还需要采取其他措施(因为它不会出现在表单字段中).

Apparently Google Website Translator does not translate input element values, even when set in HTML source. I tested with a textarea element too, with the same result. However, it does translate user input via an element other than a form field; such elements can be created using the contenteditable attribute, which is widely (though not quite universally) supported in modern browsers. But extra measures would be needed to make the translated text to be submitted along with a form (since it won’t be in a form field).

在我的书通过JavaScript和Globalize.js走向全球中,我描述了一些有关自动翻译的问题,并建议尽管通常在网页上安装小部件可能不是一个好主意,但这对于用户输入可能很有用.例如,考虑使用英语进行讨论的讨论论坛.您可以添加功能,使每个人都可以使用他的母语,将其立即翻译为英语,将其签出并提交.有一个简单的演示: 用户输入的翻译. (它使用contenteditable元素,并将翻译后的内容写到隐藏字段中.)

In my book Going Global with JavaScript and Globalize.js, I describe some of the issues in automatic translation and suggest that although it might not be a good idea to have widgets for it on web pages in general, it could be useful for user input. For example, consider a discussion forum where discussions take place in English. You could add functionality that lets everyone use his native language, have it instantly translated into English, check it out, and submit it. There’s a simple demo of this: Translation of user input. (It uses a contenteditable element and writes the translated content into a hidden field.)

这篇关于Google翻译工具不适用于输入类型的文本值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆