Skip to content

Instantly share code, notes, and snippets.

@ronanguilloux
Created March 19, 2011 05:32
Show Gist options
  • Select an option

  • Save ronanguilloux/877247 to your computer and use it in GitHub Desktop.

Select an option

Save ronanguilloux/877247 to your computer and use it in GitHub Desktop.
Very Simple Google Translate REST PHP-CLI client
#!/usr/bin/php5
<?php
/* Very Simple Google Translate REST client
* Created on march 19th 2011 ronan.guilloux
* @author ronan.guilloux
* @license http://www.gnu.org/licenses/agpl.txt GNU AFFERO GPL v3
* @version 1.0
*/
// API Key available here : https://code.google.com/apis/console/, for dev purpose only
// URL model : http://www.googleapis.com/language/translate/v2?key=APIKEY&q=WORD&source=en&target=fr&callback=handleResponse
// You shoud add a shortcut in your ~/.bashrc : alias gtr='php ~/shell/googleTranslate.php'
// usage : gtr lazy
$key = 'MyAPIKey'; // see https://code.google.com/apis/console/
$word = trim($argv[1]);
$url = 'https://www.googleapis.com/language/translate/v2?key=%s&q=%s&source=en&target=fr&callback=handleResponse';
$url = sprintf($url, $key, $word);
//echo 'fetching ' . $url;
echo "\n" . file_get_contents($url) . "\n";
?>
@ornicar
Copy link
Copy Markdown

ornicar commented Mar 19, 2011

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