我的问题是,我们可以用英语输入一个文本框,在按空格或输入键时,我们可以将它音译为印地语(其他语言)。但是要求输出应该在另一个文本框中。
那件事怎么可能?
这是我的代码,它可以音译成同一个文本框。
<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]]);
}
发布于 2014-03-10 10:14:01
started#workingWithData你需要从谷歌那里购买许可证才能使用谷歌翻译API。
'https://www.googleapis.com/language/translate/v2?key=YOUR-API-KEY&source=en&target=de&callback=translateText&q=‘+ sourceText;
https://stackoverflow.com/questions/22297203
复制相似问题