Articles → JAVASCRIPT → Convert English Text To Hindi Using Google API in JavaScript

Convert English Text To Hindi Using Google API in JavaScript






Steps


  1. First of all create a new HTML page.
  2. Add a reference of Google’s API on the page
  3. <script type="text/javascript" src="gtransapi.js"></script>


  4. Add a textbox that can be used to show the conversion.
  5. <textarea id="transliterateTxtBox" rows="10" cols="100"></textarea>


  6. Finally add JavaScript code and specify the source and destination language
  7. <script type="text/javascript">
        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
            };
    
            var control =
                new google.elements.transliteration.TransliterationControl(options);
            control.makeTransliteratable(['transliterateTxtBox']);
        }
        google.setOnLoadCallback(onLoad);
    </script>




Picture showing



Complete Code


<html>
<head>
    

    <script type="text/javascript" src="gtransapi.js"></script>

</head>
<body>
<textarea id="transliterateTxtBox" rows="10" cols="100"></textarea>



</body>

</html>
<script type="text/javascript">
    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
        };

        var control =
            new google.elements.transliteration.TransliterationControl(options);
        control.makeTransliteratable(['transliterateTxtBox']);
    }
    google.setOnLoadCallback(onLoad);
</script>

Try It


Posted By  -  Karan Gupta
 
Posted On  -  Monday, May 11, 2015
 
Updated On  -  Saturday, August 13, 2022

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250