【问题标题】:Google Transliteration - word suggestion while typing谷歌音译 - 输入时的单词建议
【发布时间】:2016-02-09 10:43:40
【问题描述】:

我在我的项目中使用 google 音译。我尝试了Google Transliterate API Developer's Guide 上提供的代码 sn-p。但是,可用的文档较少,我对此知之甚少。

代码的工作方式是仅在您按空格键时才会将单词转换为目标语言。按退格键后它会给出建议。我需要它以一种在您输入字符并同时提供建议时将单词转换为的方式工作。

以下是我从网站上尝试的 sn-p:

<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 onLoad() {
            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>

【问题讨论】:

  • 此代码有效。仅当您按空格键时,它才会将单词转换为目标语言。按退格键后它会给出建议。但我在输入字符时需要建议。帮我整理一下。
  • Google Transliterate API 已于 2011 年 5 月 26 日正式弃用。请参考此 URL 获取新 API cloud.google.com/translate/docs/quickstart

标签: javascript google-api search-suggestion transliteration


【解决方案1】:

我认为 Google 不允许改变这一点。它只是控制您的文本区域并执行它自己的脚本,我们对此没有太多控制权。

【讨论】:

  • 您有什么建议吗?我现在正在使用谷歌输入工具 API。但这也很棘手。必须明确地处理太多事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
  • 2016-01-11
相关资源
最近更新 更多