javascript 如何在网站中使用谷歌输入工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28707899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:25:09  来源:igfitidea点击:

How to Use Google Input Tools in Website

javascriptjquery

提问by Suffii

Can you please let me know if it is possible to use Google Input Tools in a website using client side scripting like jquery or pure javascript? Is there any API available for Google Input Tools?

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

I already google this but couldn't find any thing?

我已经谷歌了这个但找不到任何东西?

Thanks

谢谢

回答by Parvathy Nair

If you want to add google input tools you can use below code to add it

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

    
      // 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>

回答by Dilhan Jayathilake

Pravathy's answer worked for me as well. Just adding following google docs url if someone looks more details.

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

Google Docs

谷歌文档