将英语翻译成印地语谷歌音译

时间:2016-07-16 17:31:12

标签: javascript php

我想将英语翻译成印地语并将其保存为PHP变量。

这是谷歌的官方代码。转换后的文本也有一个文本区域。

问题:有没有办法将此文本保存在变量中?

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

1 个答案:

答案 0 :(得分:-1)

怎么样

Character

myPhp.php

var myVariable=document.getElementById("transliterateTextarea").innerText;

var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET", "myPhp.php?t=" + myVariable, true);
xhttp.send();