type in Hindi using JavaScript

1.6k views Asked by At

I am developing a website with Hindi font. The requirement is user should be able to type in Hindi or if user copy content in the text area, it should automatically convert into Hindi.

Using below-given code, When user type any word like ‘welcom‘ and then type space it will automatically convert into ‘वेलकम‘ but the below-given code is not able to convert the full sentence into Hindi like if User copy "aaj ghar jana hai" into text area It converts into Hindi only last word, not full sentence. But my requirement is to convert the sentence into Hindi also, not the only word.

Implementation is -

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to type in Hindi language in text box</title>   
    <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: 'en',
                        destinationLanguage: [google.elements.transliteration.LanguageCode.HINDI],         
                        transliterationEnabled: true
                };   

                var control = new google.elements.transliteration.TransliterationControl(options);  
                var ids = [ "first_name"];  
                alert(ids);
                control.makeTransliteratable(ids);
        }
      google.setOnLoadCallback(onLoad);
    </script>
</head>
<body>
    <table width="50%" style="border:1px solid #06F;background-color:#CFC">
     <tR>
         <td>Input :</td>
            <Td><input type="text" name="first_name" id="first_name"></Td>
        </tR>
    </table>
</body>
</html>

Please help.

0

There are 0 answers