Articles → JAVASCRIPT → Convert English Text To Hindi Using Google API in JavaScript
Convert English Text To Hindi Using Google API in JavaScript
Steps
- First of all create a new HTML page.
- Add a reference of Google’s API on the page
<script type="text/javascript" src="gtransapi.js"></script>
- Add a textbox that can be used to show the conversion.
<textarea id="transliterateTxtBox" rows="10" cols="100"></textarea>
- Finally add JavaScript code and specify the source and destination language
<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>
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