Enable to type in other language

梦想的初衷 提交于 2019-12-10 12:28:00

问题


How can I enable user to type in Bengali in textarea in my website's textarea using Google's feature which can automatically translate typed English word to proper Bengali word ?


回答1:


*BEfore that signup for the API key http://code.google.com/apis/loader/signup.html*
<pre>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="https://www.google.com/jsapi?key=INSERT-YOUR-KEY">
    </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.BENGALI],
            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 BENGALI (Press Ctrl+g to toggle between English and BENGALI)<br>
    <textarea id="transliterateTextarea" style="width:600px;height:200px"></textarea>
  </body>
</html> 
</pre>



回答2:


you can use Google AJAX Language API - Tools for Translation and Language Detection, using this function,

google.language.translate('Gato', 'es', 'en', function(result) {
  alert(result.translation);
});  

for complete reference, visit Google Ajax api




回答3:


<script type="text/javascript">

  // Load the Google Transliterate API
  google.load("elements", "1", {
        packages: "transliteration"
      });

  function onLoad() {
    var options = {
        sourceLanguage:'en', // from english
        destinationLanguage:['or'], // to oriya
        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(['TEXT_BOX_ID']);
  }
  google.setOnLoadCallback(onLoad);
</script>

Please check these details to proper documentation https://developers.google.com/transliterate/v1/getting_started?hl=en



来源:https://stackoverflow.com/questions/9043449/enable-to-type-in-other-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!