Translating with Google API

Google provides an AJAX API for translating your text into any language you need.

Since Google does not provide us with their whole language database and algorithms,but somewhere in their AJAX script they are requesting data from their server. Using the location that the script requests the data, we can request the data ourselves.

Belove is a small example using google translation API :-


function google_translate_api( $your_text, $destination_lang , $source_lang ) {

$your_text = urlencode( $your_text );
$destination_lang = urlencode( $destination_lang );
$source_lang = urlencode( $source_lang );

$trans = @file_get_contents( “{$your_text}&langpair={$source_lang}|{$destination_lang}” );
$json = json_decode( $trans, true );

if( $json[‘responseStatus’] != ‘200’ )
return false; else return $json[‘responseData’][‘translatedText’];
$sourec_text = “Good morning,have a nice day,everything is good here”;
$val = google_translate_api($sourec_text,’ru’,’en’);
echo “<pre>”;
print_r(“<h2>English Text:</h2>”.$sourec_text);
echo “<br>”;
echo “<br>”;
print_r(“<h2>Translated Russian Text:</h2>”.$val);
echo “</pre>”;


English Text: Good morning,have a nice day,everything is good here
Translated Russian Text:Доброе утро, имеют хороший день, все здесь хорошо

I like to hear from you about this !!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.