Google +1 Button using Javascript

The easiest method for including google +1 button on your web page is to include the necessary JavaScript resource and to add a +1 button tag.

Just add below tag into your HTML where you want to put google +1 button.

<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone"></div>

Add below java script into your head section.

<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>

That’s it.
You can find all other parameters at https://developers.google.com/+/plugins/+1button/

Advertisements

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 :-

<?php

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( “http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q={$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>”;
?>

Output:

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