Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transliterating english to Kannada
<?php
/**
Trasliterate method takes 5 , seaparated english words and transliterates them into Kannada,
The result is an array of words in the same order. This uses Non public Google online transliteration API for this.
When you run this method give a 10ms seconds gap between each call to be on the safer side.
By : Thejesh GN http://thejeshgn.com
More: http://thejeshgn.com/2011/02/04/batch-transliterating-names-into-kannada-using-google-api/
**/
function transliterate($comma_seaparated_words){
$api_url = "http://www.google.com/transliterate/indic?tlqt=1&langpair=en|kn&text=".$comma_seaparated_words."&&tl_app=1";
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$api_url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
$traliterated_return;
if (empty($buffer))
{
print "Sorry, example.com are a bunch of poopy-heads.<p>";
}
else
{
//JSON returned by google is not right, so hacking it.
$r = str_replace(",\n]","]", $buffer);
$j = json_decode($r);
$traliterated_return[0] = $j[0]->hws[0];
$traliterated_return[1] = $j[1]->hws[0];
$traliterated_return[2] = $j[2]->hws[0];
$traliterated_return[3] = $j[3]->hws[0];
$traliterated_return[4] = $j[4]->hws[0];
}
return $traliterated_return;
}
/* Test run starts
returns are in UTF-8 format, hence setting the charset
*/
print "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>";
$kn = transliterate("thejesh,ramesh,uthara,shreenivasa,reddy");
print $kn[0]."<p>";
print $kn[1]."<p>";
print $kn[2]."<p>";
print $kn[3]."<p>";
print $kn[4]."<p>";
/* Test run ends*/
?>
@thejeshgn

This comment has been minimized.

Owner

thejeshgn commented May 6, 2011

Trasliterate method takes 5 , seaparated english words and transliterates them into Kannada, The result is an array of words in the same order. This uses Non public Google online transliteration API for this. When you run this method give a 10ms seconds gap between each call to be on the safer side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment