[英]Google Translate — how to force a translation via javascript?
We have a partial translation via a language file but have many dynamic elements that we would like to use Google Translate to translate for us. 我们通过语言文件进行了部分翻译,但是有许多动态元素,我们希望使用Google Translate为我们翻译。
Is there a way to initiate a translation via javascript without the user having to select from the drop down? 有没有一种方法可以通过javascript启动翻译,而无需用户从下拉菜单中进行选择?
I think this should work, visit following link 我认为这应该可行,请访问以下链接
http://support.jimdo.com/tutorials/apps-and-plugins/how-to-add-google-translate-to-your-website/ http://support.jimdo.com/tutorials/apps-and-plugins/how-to-add-google-translate-to-your-website/
You can definitely translate the dynamic elements by picking them up and passing it to the Google Translate API using a REST request .
您可以通过选择动态元素,并使用REST请求将其传递给
Google Translate API来进行翻译 。 And you can get the response in JSON and extract the translation from it.
您可以使用JSON获取响应并从中提取翻译。
For example as shown below: 例如如下图所示:
Request
请求
GET https://www.googleapis.com/language/translate/v2/languages?key=INSERT-YOUR-KEY&target=zh-TW
Response
响应
200 OK
{
"data": {
"languages": [
{
"language": "zh-CN",
"name": "中文(簡體)"
},
{
"language": "fr",
"name": "法文"
},
...
{
"language": "en",
"name": "英文"
}
]
}
}
See more examples at Google Translate API - Using REST 在Google Translate API中查看更多示例-使用REST
Hope this helps... 希望这可以帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.