I have a text-box and I want to enter a string in language A

浪尽此生 提交于 2019-12-13 18:25:06

问题


I have a text-box, and I want to enter a string in language A and send it to Google Translate. After Google has translated it, I want to take the new string (in language B) (after translation) and store it in some variable.

How can I do it?


回答1:


The basic idea is shown in a simple example of Language Translation like this:

google.language.translate("Hello world", "en", "es", function(result) {
  if(!result.error) {
    var container = document.getElementById("translation");
    container.innerHTML = result.translation;
  }
});

translation is the id of your textbox. In this case where you put the translation result.

result is the translation itself. You can assign it to a new variable in any way you want.

In the above example you're translating "Hello world" from "en" (English) to "es" (Spanish).

The above code is written in JavaScript.

Take a look at Google AJAX Language API for more detailed steps.




回答2:


Read on Google AJAX Language API to understand how you can use Google's translation services programmatically.



来源:https://stackoverflow.com/questions/2397103/i-have-a-text-box-and-i-want-to-enter-a-string-in-language-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!