English to Hindi / English to Nepali Typing Using Google API

1 min read

In this article, we are going to integrate Google Transliterate API to convert English text to corresponding text in other language like Hindi or Nepali.

For this, we will need two files

  • jsapi.js
  • index.html

index.html

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

<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(['english-input']);
  }
  
  google.setOnLoadCallback(onLoad);
</script>

<textarea id="english-input" name="english-input" rows="8" ></textarea>

 

A lot of language options are available for this. Some of them are listed below :

  • Amharic
  • Arabic
  • Bengali
  • Chinese
  • Greek
  • Gujarati
  • Hindi
  • Kannada
  • Malayalam
  • Marathi
  • Nepali
  • Oriya
  • Persian
  • Punjabi
  • Russian
  • Sanskrit
  • Serbian
  • Sinhalese
  • Tamil
  • Telugu
  • Tigrinya
  • Urdu

Download jsapi.js file from here : Click Here to Download jsapi.js

Recommended For You

About the Author: Ritesh Ghimire