【问题标题】:Enable to type in other language允许输入其他语言
【发布时间】:2012-02-21 00:59:58
【问题描述】:

如何让用户使用谷歌的功能在我网站的 textarea 中的 textarea 中输入孟加拉语,该功能可以自动将输入的英语单词翻译成正确的孟加拉语单词?

【问题讨论】:

    标签: php google-translate


    【解决方案1】:
    <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>
    

    请检查这些详细信息以获取正确的文档 https://developers.google.com/transliterate/v1/getting_started?hl=en

    【讨论】:

      【解决方案2】:

      您可以使用 Google AJAX Language API - Tools for Translation and Language Detection,使用此功能,

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

      如需完整参考,请访问Google Ajax api

      【讨论】:

        【解决方案3】:
        *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>
        

        【讨论】:

          猜你喜欢
          • 2017-08-20
          • 2017-08-30
          • 1970-01-01
          • 2011-09-29
          • 1970-01-01
          • 2017-01-23
          • 1970-01-01
          • 2020-06-13
          • 1970-01-01
          相关资源
          最近更新 更多