It is known that spacebar must be pressed to translate while using google transliteration.
But requirement is to translate already stored value in input fetched from database, not a live user typed value.
I doubt we can translate input value automatically with google jspi.
It is not possible to translate without hitting spacebar so I am trying to press spacebar to each class when a specific button is clicked, so it would be translated.
For example, here is button, if this button is clicked then press spacebar to each class and translate automatically.
I tried with appending space after the value, but without spacebar event nothing change
$('#translate').click(function(){
$('.npl').each(function(){
$(this).val($(this).val()+'');
})
})
$('.npl').nepalize();
$.fn.nepalize = function(){
var that = this[0];
google.load("elements", "1", {
packages: "transliteration"
});
function onLoad() {
var options = {
sourceLanguage: 'en', // or google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage: ['ne'], // or [google.elements.transliteration.LanguageCode.HINDI],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
var control = new google.elements.transliteration.TransliterationControl(options);
// Enable transliteration in the textfields with the given Class.
var elements = document.getElementsByClassName('npl');
control.makeTransliteratable(elements);
}
google.setOnLoadCallback(onLoad);
}
$('#translate').click(function(){
$('.npl').each(function(){
$(this).val($(this).val()+'');
})
})
$('.npl').nepalize();
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
</head>
<body>
<button id='translate'>Translate</button>
<input class="npl" value='Hello'>
<input class="npl" value='How are you' />
</body>
</html>