Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to translate english to hindi after enter space using javascript

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>

<script type="text/javascript">
google.load("elements", "1", {packages: "transliteration"});
</script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
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(["txtHindi"]);
    var keyVal = 32; // Space key
    $("#txtEnglish").on('keydown', function(event) {
        if(event.keyCode === 32) {
            var engText = $("#txtEnglish").val() + " ";
            var engTextArray = engText.split(" ");
            $("#txtHindi").val($("#txtHindi").val() + engTextArray[engTextArray.length-2]);

            document.getElementById("txtHindi").focus();
            $("#txtHindi").trigger ( {
                type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
            } );
        }
    });

    $("#txtHindi").bind ("keyup",  function (event) {
        setTimeout(function(){ $("#txtEnglish").val($("#txtEnglish").val() + " "); document.getElementById("txtEnglish").focus()},0);
    });
} //end onLoad function

google.setOnLoadCallback(OnLoad);
</script> 

</head>
    <body>
       English Text: <input size="40" type="text" id="txtEnglish"/> <br/>
       Hindi Text`enter code here` : <input size="40" type="text" id="txtHindi"/> 
</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: llamar a un segundo back 
Javascript :: remove state from location on page load in react router dom 
Javascript :: monk remove 
Javascript :: json identifier with period 
Javascript :: scala play json read single field 
Javascript :: rest operator javascript 
Javascript :: parse ipv6 address using json 
Javascript :: jquery not calling id from div called in ajax 
Javascript :: node express table view 
Javascript :: alaa 201 exam 
Javascript :: get selected value on componentdidmount reactjs 
Javascript :: News Application With Angular and Material Design 
Javascript :: prefix increment 
Javascript :: math.pow vs math.exp 
Javascript :: is typescript slower than javascript 
Javascript :: how to check record successfully delete in mongodb node js 
Javascript :: js swap 
Javascript :: this rule in js:medium 
Javascript :: js nvl function 
Javascript :: javascript linkify string text 
Javascript :: force update function component after fetch data second time 
Javascript :: ngx-search clearing-imp 
Javascript :: es6 features in javascript 
Javascript :: plyr.js example in angular 10 
Javascript :: jquery to vanilla js converter 
Javascript :: get value of telerik combo box js 
Javascript :: jquery listen for click on class that was created later 
Javascript :: how to push an object into an array in reducer 
Javascript :: 4.2. Type Conversion¶ 
Javascript :: how to share variables between routes node 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =