JavaScript/jQuery - 获取文本并翻译它
是否可以使用 jQuery 从元素中获取文本并将其翻译为其他语言?
之前
<p>Hello</p>
之后
<p>bonjour</p>
Is it possible to use jQuery to get a text from an element and translate it to other languages?
Before
<p>Hello</p>
After
<p>bonjour</p>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用这个 JQuery 插件
https://github.com/tinoni/translate.js
免责声明:我是作者
1 -将“trn”类包含到要翻译的文本中:
2 - 定义字典:
3 - 翻译整个页面正文:
4 - 更改为另一种语言:
Use this JQuery plugin
https://github.com/tinoni/translate.js
Disclaimer: I am the author
1 - Include the "trn" class to the text you want to translate:
2 - Define a dictionary:
3 - Translate the entire page body:
4 - Change to another language:
使用谷歌翻译API。便于使用。以下将西班牙语翻译成英语。要在其他语言之间进行翻译,只需更改
'es'
和'en'
< /code>
检查工作示例 http://jsfiddle.net/wJ2QP/1/
Use Google translation API. Easy to use. The following translates Spanish to English. To translate from and to other languages, simply change
'es'
and'en'
<div id="content"></div>
Check working example at http://jsfiddle.net/wJ2QP/1/
尝试谷歌翻译:http://code.google.com/apis/language/translate /概述.html
try google translate: http://code.google.com/apis/language/translate/overview.html
您可以使用 Google 翻译的 Javascript API。
您需要在页面的 HEAD 部分加载 js 库才能使用 API。
You can use Google Translate's Javascript API.
You will need to load the js library in your page's HEAD section in order to use the API.
使用 Bing 翻译器,因为免费的 Google Translate API 已于 2011 年 12 月 1 日停止使用
Use the Bing translator, since the free Google Translate API has been discontinued on December 1, 2011
在此 PHP/JS 解决方案中,您应该使用包含 PHP 语言文件并在会话/cookie 上设置语言而不是在 $_GET 上。为了简单,我将在
index.php文件
上执行JS文件
check.php返回一个json
On this PHP/JS solution you should use include PHP language files and set language on session/cookie not on $_GET. For the sake of simplicity I will do it on the
index.php file
JS file
check.php return a json
为什么不试试这个:
它可以替代任何东西。
Why not try this:
It can replace anything.