【问题标题】:How to Use Google Input Tools in Website如何在网站中使用 Google 输入工具
【发布时间】:2015-02-24 22:48:30
【问题描述】:

您能否告诉我是否可以在使用客户端脚本(如 jquery 或纯 javascript)的网站中使用 Google 输入工具?是否有任何 API 可用于 Google 输入工具?

我已经用谷歌搜索了,但找不到任何东西?

谢谢

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    如果你想添加谷歌输入工具,你可以使用下面的代码来添加它

        
          // Load the Google Transliteration API
          google.load("elements", "1", {
            packages: "transliteration"
          });
        
          function onLoad() {
            var options = {
              sourceLanguage: 'en',
              destinationLanguage: ['gu', 'ml', 'hi', 'kn', 'ta', 'te'],
              shortcutKey: 'ctrl+m',
              transliterationEnabled: true
            }
        
            // Create an instance on TransliterationControl with the required options.
            var control = new google.elements.transliteration.TransliterationControl(options);
        
            // Enable transliteration in the textfields with the given ids.
            var ids = ["language"];
            control.makeTransliteratable(ids);
        
            // Show the transliteration control which can be used to toggle between English and Hindi and also choose other destination language.
            control.showControl('translControl');
          }
        
          google.setOnLoadCallback(onLoad);
        
    
     
        
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
      
    <textarea name="hi"  rows="6"  id="language" cols="6" style="width:600px;height:70px" ></textarea>
    
    <div id='translControl'></div>

    【讨论】:

    • 谢谢,这对我有帮助。但是我发现了一个问题,它只在笔划“空格键”之后提示这个词,是否可以列出每个按键的提示?
    • 我在 jquery 中使用它,但它不能正常工作
    • 这个答案给出了音译api的例子,而不是使用IME(输入法编辑器)。音译是指基于语音相似性从一种书写系统映射到另一种书写系统的方法。例如,在印地语音译中,您可以输入“namaste”来获得“नमस्ते”,这听起来像“namaste”。输入法编辑器 (IME) 将击键转换为另一种语言的字符。
    • 很好,但我的问题是在同一页面中多次使用此脚本?
    • @SanjayaPandey:你找到解决方案了吗? (对每个按键的建议)我非常需要这个。提前致谢。
    【解决方案2】:

    Pravathy 的回答也对我有用。如果有人查看更多详细信息,只需添加以下 google docs url。

    Google Docs

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多