我有一个文本框,我想用语言A输入一个字符串 [英] I have a text-box and I want to enter a string in language A

查看:75
本文介绍了我有一个文本框,我想用语言A输入一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,我想用语言A输入一个字符串并将其发送给 Google翻译. Google翻译完之后,我想将新的字符串(使用B语言)(翻译后)保存在某个变量中.

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.

我该怎么办?

推荐答案

基本概念显示在一个简单的语言翻译示例中,如下所示:

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是文本框的ID.在这种情况下,您要放置翻译结果.

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

result是翻译本身.您可以根据需要将其分配给新变量.

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

在上面的示例中,您正在将"Hello world"从"en"(英语)翻译为"es"(西班牙语).

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

上面的代码是用JavaScript编写的.

The above code is written in JavaScript.

请查看 Google AJAX语言API ,以获取更详细的步骤.

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

这篇关于我有一个文本框,我想用语言A输入一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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