Friday, September 6, 2013

Converting One Language from Another Language In Asp.Net

Converting One Language from Another Language In Asp.Net




Step1:-Add these to scripts in the top of the page
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

Step2:-Create two text like this
<table id="tabel1" align="center" border="2">
            <tr>
                <td>
                    <h1>
                        Converting One Language from Another Language In Asp.Net using Google</h1>
                    <asp:TextBox ID="transliterateTextarea" runat="server" Height="47px" Width="365px"></asp:TextBox>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="Textarea1" runat="server" Height="43px" Width="375px"></asp:TextBox>
                    <h6>
                        Here Showing English to Hindi</h6>
                </td>
            </tr>
        </table>

Step3:-After that add this script data below the 2 url scripts
<script type="text/javascript">

        var InputData = [];
        var string="";
        //Load the Language API.
        google.load("language", "1");
        //Call google.language.transliterate()
        function test() {
            $('#transliterateTextarea').keyup(function (event) {
                var regex = new RegExp("^[a-zA-Z0-9]+$");
                var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
                if (regex.test(key)) {
                    string = string + key;
                }
                else {
                    if (string != "") {
                        google.language.transliterate([string], "en", "hi", function (result) {
                            if (!result.error) {
                                if (result.transliterations && result.transliterations.length > 0 && result.transliterations[0].transliteratedWords.length > 0) {
                               
                                    document.getElementById('<%=Textarea1.ClientID %>').value = document.getElementById('<%=Textarea1.ClientID %>').value + result.transliterations[0].transliteratedWords[0]+event.char;
                                    string = "";
                                    if (event.keyCode == 8 || event.keyCode == 46) {
                                        document.getElementById('<%=Textarea1.ClientID %>').value = "";
                                        document.getElementById('<%=transliterateTextarea.ClientID %>').value = "";
                                        string = "";
                                    }
                                }
                            }
                            else {
                                document.getElementById('<%=Textarea1.ClientID %>').value = "";
                                document.getElementById('<%=transliterateTextarea.ClientID %>').value = "";
                                string = "";
                            }
                        });
                    }

                }
                if (event.keyCode == 8 || event.keyCode == 46) {
                    document.getElementById('<%=Textarea1.ClientID %>').value = "";
                    document.getElementById('<%=transliterateTextarea.ClientID %>').value = "";
                    string = "";
                }
            });
        }
        google.setOnLoadCallback(test);

    </script>

The whole content of the script looks like
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <title>Converting One Language from Another Language In Asp.Net</title>
    <script type="text/javascript">

        var InputData = [];
        var string="";
        //Load the Language API.
        google.load("language", "1");
        //Call google.language.transliterate()
        function test() {
            $('#transliterateTextarea').keyup(function (event) {
                var regex = new RegExp("^[a-zA-Z0-9]+$");
                var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
                if (regex.test(key)) {
                    string = string + key;
                }
                else {
                    if (string != "") {
                        google.language.transliterate([string], "en", "hi", function (result) {
                            if (!result.error) {
                                if (result.transliterations && result.transliterations.length > 0 && result.transliterations[0].transliteratedWords.length > 0) {
                                
                                    document.getElementById('<%=Textarea1.ClientID %>').value = document.getElementById('<%=Textarea1.ClientID %>').value + result.transliterations[0].transliteratedWords[0]+event.char;
                                    string = "";
                                    if (event.keyCode == 8 || event.keyCode == 46) {
                                        document.getElementById('<%=Textarea1.ClientID %>').value = "";
                                        document.getElementById('<%=transliterateTextarea.ClientID %>').value = "";
                                        string = "";
                                    }
                                }
                            }
                            else {
                                document.getElementById('<%=Textarea1.ClientID %>').value = "";
                                document.getElementById('<%=transliterateTextarea.ClientID %>').value = "";
                                string = "";
                            }
                        });
                    }

                }
                if (event.keyCode == 8 || event.keyCode == 46) {
                    document.getElementById('<%=Textarea1.ClientID %>').value = "";
                    document.getElementById('<%=transliterateTextarea.ClientID %>').value = "";
                    string = "";
                }
            });
        }
        google.setOnLoadCallback(test);

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="tabel1" align="center" border="2">
            <tr>
                <td>
                    <h1>
                        Converting One Language from Another Language In Asp.Net using Google</h1>
                    <asp:TextBox ID="transliterateTextarea" runat="server" Height="47px" Width="365px"></asp:TextBox>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="Textarea1" runat="server" Height="43px" Width="375px"></asp:TextBox>
                    <h6>
                        Here Showing English to Hindi</h6>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


Output











For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 

No comments:

Post a Comment