Hi, I used this code to translate in any language, what I am typing . It is working good. But, for English, I don`t know how to do?
can anybody know it?

<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"
          });

      var transliterationControl;
      function onLoad() {
        var options = {
            sourceLanguage: 'en',
            destinationLanguage: ['ar','hi','kn','ml','ta','te'],
            transliterationEnabled: true,
            shortcutKey: 'ctrl+g'
        };
        // Create an instance on TransliterationControl with the required
        // options.
        transliterationControl =
          new google.elements.transliteration.TransliterationControl(options);

        // Enable transliteration in the textfields with the given ids.
        var ids = [ "transl1", "transl2" ];
        transliterationControl.makeTransliteratable(ids);

        // Add the STATE_CHANGED event handler to correcly maintain the state
        // of the checkbox.
        transliterationControl.addEventListener(
            google.elements.transliteration.TransliterationControl.EventType.STATE_CHANGED,
            transliterateStateChangeHandler);

        // Add the SERVER_UNREACHABLE event handler to display an error message
        // if unable to reach the server.
        transliterationControl.addEventListener(
            google.elements.transliteration.TransliterationControl.EventType.SERVER_UNREACHABLE,
            serverUnreachableHandler);

        // Add the SERVER_REACHABLE event handler to remove the error message
        // once the server becomes reachable.
        transliterationControl.addEventListener(
            google.elements.transliteration.TransliterationControl.EventType.SERVER_REACHABLE,
            serverReachableHandler);

        // Set the checkbox to the correct state.
        document.getElementById('checkboxId').checked =
          transliterationControl.isTransliterationEnabled();

        // Populate the language dropdown
        var destinationLanguage =
          transliterationControl.getLanguagePair().destinationLanguage;
        var languageSelect = document.getElementById('languageDropDown');
        var supportedDestinationLanguages =
          google.elements.transliteration.getDestinationLanguages(
            google.elements.transliteration.LanguageCode.ENGLISH);
        for (var lang in supportedDestinationLanguages) {
          var opt = document.createElement('option');
          opt.text = lang;
          opt.value = supportedDestinationLanguages[lang];
          if (destinationLanguage == opt.value) {
            opt.selected = true;
          }
          try {
            languageSelect.add(opt, null);
          } catch (ex) {
            languageSelect.add(opt);
          }

        }
      }

      // Handler for STATE_CHANGED event which makes sure checkbox status
      // reflects the transliteration enabled or disabled status.
      function transliterateStateChangeHandler(e) {
        document.getElementById('checkboxId').checked = e.transliterationEnabled;
      }

      // Handler for checkbox's click event.  Calls toggleTransliteration to toggle
      // the transliteration state.
      function checkboxClickHandler() {
        transliterationControl.toggleTransliteration();
      }

      // Handler for dropdown option change event.  Calls setLanguagePair to
      // set the new language.
      function languageChangeHandler() {
        var dropdown = document.getElementById('languageDropDown');
        transliterationControl.setLanguagePair(
            google.elements.transliteration.LanguageCode.ENGLISH,
            dropdown.options[dropdown.selectedIndex].value);
      }

      // SERVER_UNREACHABLE event handler which displays the error message.
      function serverUnreachableHandler(e) {
        document.getElementById("errorDiv").innerHTML =
            "Transliteration Server unreachable";
      }

      // SERVER_UNREACHABLE event handler which clears the error message.
      function serverReachableHandler(e) {
        document.getElementById("errorDiv").innerHTML = "";
      }
      google.setOnLoadCallback(onLoad);

    </script>
  </head>
  <body>
  <center>Type in Indian languages (Press Ctrl+g to toggle between English and Hindi)</center>
    <div id='translControl'>
      <input type="checkbox" id="checkboxId" onClick="javascript:checkboxClickHandler()"></input>
      Type in <select id="languageDropDown" onChange="javascript:languageChangeHandler()"></select>
    </div>
    <br>Title : <input type='textbox' id="transl1"/>
    <br>Body<br><textarea id="transl2" style="width:600px;height:200px"></textarea>
    <br><div id="errorDiv"></div>
  </body>
</html>
Member Avatar for Rahul47

It is working for English too. What are you trying to do ? Please specify.

 This code has to check for typing in English.
    <script type="text/javascript">

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

          var transliterationControl;
          function onLoad() {
            var options = {
                sourceLanguage: 'en',
                destinationLanguage: ['ar','hi','kn','ml','ta','te'],
                transliterationEnabled: true,
                shortcutKey: 'ctrl+g'
            };
            // Create an instance on TransliterationControl with the required
            // options.
            transliterationControl =
              new google.elements.transliteration.TransliterationControl(options);

            // Enable transliteration in the textfields with the given ids.
            var ids = [ "transl1", "transl2" ];
            transliterationControl.makeTransliteratable(ids);

            // Add the STATE_CHANGED event handler to correcly maintain the state
            // of the checkbox.
            transliterationControl.addEventListener(
                google.elements.transliteration.TransliterationControl.EventType.STATE_CHANGED,
                transliterateStateChangeHandler);

            // Add the SERVER_UNREACHABLE event handler to display an error message
            // if unable to reach the server.
            transliterationControl.addEventListener(
                google.elements.transliteration.TransliterationControl.EventType.SERVER_UNREACHABLE,
                serverUnreachableHandler);

            // Add the SERVER_REACHABLE event handler to remove the error message
            // once the server becomes reachable.
            transliterationControl.addEventListener(
                google.elements.transliteration.TransliterationControl.EventType.SERVER_REACHABLE,
                serverReachableHandler);

            // Set the checkbox to the correct state.
            document.getElementById('checkboxId').checked =
              transliterationControl.isTransliterationEnabled();

            // Populate the language dropdown
            var destinationLanguage =
              transliterationControl.getLanguagePair().destinationLanguage;
            var languageSelect = document.getElementById('languageDropDown');
            var supportedDestinationLanguages =
              google.elements.transliteration.getDestinationLanguages(
                google.elements.transliteration.LanguageCode.ENGLISH);
            for (var lang in supportedDestinationLanguages) {
              var opt = document.createElement('option');
              opt.text = lang;
              opt.value = supportedDestinationLanguages[lang];
              if (destinationLanguage == opt.value) {
                opt.selected = true;
              }
              try {
                languageSelect.add(opt, null);
              } catch (ex) {
                languageSelect.add(opt);
              }

            }
          }

          // Handler for STATE_CHANGED event which makes sure checkbox status
          // reflects the transliteration enabled or disabled status.
          function transliterateStateChangeHandler(e) {
            document.getElementById('checkboxId').checked = e.transliterationEnabled;
          }

          // Handler for checkbox's click event.  Calls toggleTransliteration to toggle
          // the transliteration state.
          function checkboxClickHandler() {
            transliterationControl.toggleTransliteration();
          }

          // Handler for dropdown option change event.  Calls setLanguagePair to
          // set the new language.
          function languageChangeHandler() {
            var dropdown = document.getElementById('languageDropDown');
            transliterationControl.setLanguagePair(
                google.elements.transliteration.LanguageCode.ENGLISH,
                dropdown.options[dropdown.selectedIndex].value);
          }

          // SERVER_UNREACHABLE event handler which displays the error message.
          function serverUnreachableHandler(e) {
            document.getElementById("errorDiv").innerHTML =
                "Transliteration Server unreachable";
          }

          // SERVER_UNREACHABLE event handler which clears the error message.
          function serverReachableHandler(e) {
            document.getElementById("errorDiv").innerHTML = "";
          }
          google.setOnLoadCallback(onLoad);

        </script>





        <div id='translControl'>
        <div class="form-group">
          <input type="checkbox" id="checkboxId" onClick="javascript:checkboxClickHandler()"/>
          <label style="font-weight:bold; margin-left:4%;">Type in </label>  <select id="languageDropDown" name="languageDropDown" onChange="javascript:languageChangeHandler()" data-init-plugin="select2"></select>
          <script type="text/javascript">
         //document.arsettings.languageDropDown.value="<?php //echo @$sumakka['qa_settings_language'];?>";
          </script><!--data-init-plugin="select2"-->


      <span style="font-weight:bold; margin-left:20%;" id="ref"> Question </span> <input type='textbox' id="transl1" name="transl1" style="width:30%; margin-left:8%;" required/></div></div>

       <div class="form-group"><span style="font-weight:bold;">Answer</span><br><textarea id="transl2" name="transl2" style="width:100%;height:200px" required>
 This code has to check for typing in English.
    <script type="text/javascript">

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

          var transliterationControl;
          function onLoad() {
            var options = {
                sourceLanguage: 'en',
                destinationLanguage: ['ar','hi','kn','ml','ta','te'],
                transliterationEnabled: true,
                shortcutKey: 'ctrl+g'
            };
            // Create an instance on TransliterationControl with the required
            // options.
            transliterationControl =
              new google.elements.transliteration.TransliterationControl(options);

            // Enable transliteration in the textfields with the given ids.
            var ids = [ "transl1", "transl2" ];
            transliterationControl.makeTransliteratable(ids);

            // Add the STATE_CHANGED event handler to correcly maintain the state
            // of the checkbox.
            transliterationControl.addEventListener(
                google.elements.transliteration.TransliterationControl.EventType.STATE_CHANGED,
                transliterateStateChangeHandler);

            // Add the SERVER_UNREACHABLE event handler to display an error message
            // if unable to reach the server.
            transliterationControl.addEventListener(
                google.elements.transliteration.TransliterationControl.EventType.SERVER_UNREACHABLE,
                serverUnreachableHandler);

            // Add the SERVER_REACHABLE event handler to remove the error message
            // once the server becomes reachable.
            transliterationControl.addEventListener(
                google.elements.transliteration.TransliterationControl.EventType.SERVER_REACHABLE,
                serverReachableHandler);

            // Set the checkbox to the correct state.
            document.getElementById('checkboxId').checked =
              transliterationControl.isTransliterationEnabled();

            // Populate the language dropdown
            var destinationLanguage =
              transliterationControl.getLanguagePair().destinationLanguage;
            var languageSelect = document.getElementById('languageDropDown');
            var supportedDestinationLanguages =
              google.elements.transliteration.getDestinationLanguages(
                google.elements.transliteration.LanguageCode.ENGLISH);
            for (var lang in supportedDestinationLanguages) {
              var opt = document.createElement('option');
              opt.text = lang;
              opt.value = supportedDestinationLanguages[lang];
              if (destinationLanguage == opt.value) {
                opt.selected = true;
              }
              try {
                languageSelect.add(opt, null);
              } catch (ex) {
                languageSelect.add(opt);
              }

            }
          }

          // Handler for STATE_CHANGED event which makes sure checkbox status
          // reflects the transliteration enabled or disabled status.
          function transliterateStateChangeHandler(e) {
            document.getElementById('checkboxId').checked = e.transliterationEnabled;
          }

          // Handler for checkbox's click event.  Calls toggleTransliteration to toggle
          // the transliteration state.
          function checkboxClickHandler() {
            transliterationControl.toggleTransliteration();
          }

          // Handler for dropdown option change event.  Calls setLanguagePair to
          // set the new language.
          function languageChangeHandler() {
            var dropdown = document.getElementById('languageDropDown');
            transliterationControl.setLanguagePair(
                google.elements.transliteration.LanguageCode.ENGLISH,
                dropdown.options[dropdown.selectedIndex].value);
          }

          // SERVER_UNREACHABLE event handler which displays the error message.
          function serverUnreachableHandler(e) {
            document.getElementById("errorDiv").innerHTML =
                "Transliteration Server unreachable";
          }

          // SERVER_UNREACHABLE event handler which clears the error message.
          function serverReachableHandler(e) {
            document.getElementById("errorDiv").innerHTML = "";
          }
          google.setOnLoadCallback(onLoad);

        </script>





        <div id='translControl'>
        <div class="form-group">
          <input type="checkbox" id="checkboxId" onClick="javascript:checkboxClickHandler()"/>
          <label style="font-weight:bold; margin-left:4%;">Type in </label>  <select id="languageDropDown" name="languageDropDown" onChange="javascript:languageChangeHandler()" data-init-plugin="select2"></select>
          <script type="text/javascript">
         //document.arsettings.languageDropDown.value="<?php //echo @$sumakka['qa_settings_language'];?>";
          </script><!--data-init-plugin="select2"-->


      <span style="font-weight:bold; margin-left:20%;" id="ref"> Question </span> <input type='textbox' id="transl1" name="transl1" style="width:30%; margin-left:8%;" required/></div></div>

       <div class="form-group"><span style="font-weight:bold;">Answer</span><br><textarea id="transl2" name="transl2" style="width:100%;height:200px" required>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.