我的问题是我们可以输入英文文本框,按空格键或输入键我们可以将其音译成印地文(其他语言)。但要求是输出应该在另一个文本框中。
这怎么可能?
这是我的代码,它会翻译成相同的文本框
<div>
<asp:TextBox runat="server" Height="30px" ID="TextBox1" Width="200px" />
</div>
<script>
attachControlgglTransliterate("TextBox1");
</script>
这是google提供的js(translt.js文件)代码。
function loadGoogle() {
try {
if (google) {
// Load the Google Transliterate API
google.load("elements", "1", {
packages: "transliteration"
});
}
else setTimeout(function () { loadGoogle() }, 100);
} catch (e) {
setTimeout(function () { loadGoogle() }, 100);
}
}
loadGoogle();
var gglTrnsLitrt = null;
// Create an instance on TransliterationControl with the required
// options.
var control = null;
function attachControlgglTransliterate(ctrl,language) {
// alert(1);
// alert(ctrl.id);
// alert(language);
try {
if (control == null) {
if (google.elements.transliteration != null) {
if (language == "0") {
gglTrnsLitrt = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.HINDI],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
control = new google.elements.transliteration.TransliterationControl(gglTrnsLitrt);
}
}
else { setTimeout(function () { attachControlgglTransliterate(ctrl,language) }, 1000); }
}
} catch (e) {
setTimeout(function () { attachControlgglTransliterate(ctrl,language) }, 1000);
}
var listControls = ctrl.split("~");
for (i = 0; i < listControls.length; i++) {
control.makeTransliteratable([listControls[i]]);
}
答案 0 :(得分:0)
https://developers.google.com/translate/v2/getting_started#workingWithData您需要从Google购买许可才能使用Google翻译API。
'https://www.googleapis.com/language/translate/v2?key= 您的API密钥&amp; source = zh&amp; target = de&amp; callback = translateText&amp; q ='+ sourceText;