javascript – Google Transliteration – 输入时的字词建议
作者:互联网
我在我的项目中使用谷歌音译.我尝试了Google Transliterate API Developer’s Guide上提供的代码片段.但是,可用的文档较少,而且我对此知之甚少.
代码的工作方式是只有在按空格时才将单词转换为目标语言.按退格键后会给出建议.我需要以一种方式工作,它会将字词转换为当您键入字符并同时提供建议时.
以下是我在网站上尝试的代码段:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Google Transliterate API
google.load("elements", "1", {
packages: "transliteration"
});
function onl oad() {
var options = {
sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:[google.elements.transliteration.LanguageCode.HINDI],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
// Create an instance on TransliterationControl with the required
// options.
var control = new google.elements.transliteration.TransliterationControl(options);
// Enable transliteration in the textbox with id
// 'transliterateTextarea'.
control.makeTransliteratable(['transliterateTextarea']);
}
google.setOnLoadCallback(onLoad);
</script>
</head>
<body>
Type in Hindi (Press Ctrl+g to toggle between English and Hindi)<br>
<textarea id="transliterateTextarea" style="width:600px;height:200px"></textarea>
</body>
</html>
解决方法:
我认为谷歌不允许改变这一点.它只是控制你的文本区域并执行它自己的脚本,我们没有太多的控制权.
标签:javascript,google-api,transliteration,search-suggestion 来源: https://codeday.me/bug/20190706/1396712.html