Language Transliteration using Google API
This article explains how to use Google Transliteration using Google API
Contents |
Introduction
Google has changed the developer's life by providing various API. The Google maps API is very popular among the developers for location based services. There is one more popular API being used by developers to translate information from one language to another i.e. "Google Transliterate API". This article demonstrates how to use the Google's Transliterate API using Nokia Web Runtime. Since I belong to India, I have used the transliteration from English to Hindi. The more details about this API can be obtained from Language API.
Getting started
Create a blank project "Symbian Web App (wgz)" using Nokia Web Tools. Follow the simple steps to create the basic layouts. It will create main three files; basic.css, basic.js and index.html. I have placed all the javascript code into index.html file and hence I have not used basic.js file.
basic.css
/*
* Add your Stylesheet contents here
*/
textarea {
border-width:2px;
border-color:black;
height:180px;
width:240px
}
body {
background-color:#9ef9e3
}
index.html
<!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"/>
<title>My Hindi Page</title>
<link rel="stylesheet" href="basic.css" type="text/css" >
</head>
<body>
<script type="text/javascript" src="
https://www.google.com/jsapi"></script>
<script type="text/javascript" >
//Load the Language API.
google.load("language", "1");
function change(newVal)
{
google.language.transliterate([newVal], "en", "hi", function(result)
{
if (!result.error) {
if (result.transliterations && result.transliterations.length > 0 &&
result.transliterations[0].transliteratedWords.length > 0)
{
document.myform.destText.value = result.transliterations[0].transliteratedWords[0];
document.myform.destText.select();
}
else
{
document.myform.destText.value ="Error";
}
}
else
{
document.myform.destText.value ="Error";
}
});
}
</script>
<form name="myform" action="">
<p>English</p>
<textarea id="sourceText" ></textarea>
<p align="center">
<input type="button" id="btn" value="Convert" onclick="change(sourceText.value);" />
</p>
<p>Hindi</p>
<textarea id="destText"></textarea>
</form>
</body>
</html>
Note
This application uses Google API hence the internet charges may apply to transliterate.
(no comments yet)