Wednesday, August 20, 2014

Transliteration – JavaScript Example (ASP.net)

 

In this article I will illustrate how to convert text from one language to another in JavaScript.It can be achieved using Google API’s. There are many versions of API’s released.

here in this example i will use “jsapi” by referring following link in my web page.

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

else one can download java script file from the above link and reference it in the page.


Ex:  Suppose we have two textboxes , one for entering English text and the other to display translated text. Enter text in English and press tab , converted text will appear in another textbox.


ASPX Code :



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ex.aspx.cs" Inherits="Ex" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>

<script type="text/javascript">

google.load(
"language", "1");
function myfunction() {
var filed
= 'txtEng'
var strEngName
= document.getElementById(filed).value;
var strEngArray
= new Array();
strEngArray
= strEngName.split(" ");
var str
= '';

if (document.getElementById('txtEng').value.length == 0) {

document.getElementById(
'txtTel').value = '';

}
document.getElementById(
'txtEng').value = document.getElementById('txtEng').value.replace(/^\s+|\s+$/g, '');

for (i = 0; i < strEngArray.length; i++)
{
var temp
= strEngArray[i];

google.language.transliterate([strEngArray[i]],
"en", "te", function (result)
{
if (!result.error) {
var container
= document.getElementById('txtTel');
if (result.transliterations && result.transliterations.length > 0 && result.transliterations[0].transliteratedWords.length > 0) {


container.value
= result.transliterations[0].transliteratedWords[0];
str
= str + ' ' + container.value;

}
document.getElementById(
'txtTel').value = str;

}

}

);
}




}
google.setOnLoadCallback(myfunction);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tbody>
<tr>
<td>

Enter the Name(English)
</td>
<td>

<input id="txtEng" style="background-color:pink;width:380px; height:30px;font-size:18px;font-weight:bold" onblur="javascript:myfunction();" />
</td>

</tr>
<tr>
<td>Translated Text: </td>
<td>
<input id="txtTel" style="background-color:yellow;width:380px; height:50px;font-size:18px;font-weight:bold" />

</td>

</tr>
</tbody>

</table>
<br>
</div>
</form>
</body>
</html>


OUTPUT :


output

18 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in chennai | rpa training in chennai
    rpa training in pune | rpa online training | rpa training in bangalore

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    python training in pune | python training institute in chennai | python training in Bangalore

    ReplyDelete
  6. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    Best Devops Training in pune
    Devops interview questions and answers

    ReplyDelete
  7. Hello! This is my first visit to When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several your blog!
    fire and safety course in chennai

    ReplyDelete
  8. Thanks For Sharing The Information The information shared Is Very Valuable Please Keep Updating Us Time just went On reading The article Python Online Training Aws Online Training Hadoop Online Training Data Science Online Training

    ReplyDelete

  9. Great Post,really it was very helpful for us.
    Thanks a lot for sharing!
    I found this blog to be very useful!!
    JAVA training in Bangalore

    ReplyDelete
  10. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  11. http://sailajareddy-technical.blogspot.com/2014/08/transliteration-javascript-example.html

    ReplyDelete