Hindi Textbox using Google Translator API

To type in Hindi in Text Box use following Java Script API.

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

Write following script to to your page to initialise Textbox for the API.

 <script type="text/javascript">

          // Load the Google Transliteration API
          google.load("elements", "1", {
                packages: "transliteration"
              });
          function onLoad() {
            var options = {
              sourceLanguage: 'en',
              destinationLanguage: ['hi'],
              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 textfields with the given ids.
            var ids = [ "txtName","txtAddress"];
            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>

Here  "txtName", "txtAddress" are ID of text boxes where you need to apply the translation.

Add a Translator Language selector using following  code.

<div id='translControl' style="width:100px"></div>

where translControl is id for toggling switch.

Now add bext boxes HTML code for hindi typing.

<input name="txtName" type="text" id="txtName" />

<textarea name="txtAddress" rows="3" id="txtAddress" ></textarea>

View page on browser and you will get a hindi typing invironment.

Demo is below-

Change Language
Press Ctrl+g to toggle between English and Hindi 
Name
Address


Keywords: