Skip to content

Instantly share code, notes, and snippets.

@thejeshgn
Created February 4, 2011 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thejeshgn/811299 to your computer and use it in GitHub Desktop.
Save thejeshgn/811299 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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