Created
March 19, 2011 05:32
-
-
Save ronanguilloux/877247 to your computer and use it in GitHub Desktop.
Very Simple Google Translate REST PHP-CLI client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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"; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Neat! I use a python script to do that: https://github.com/ornicar/dotfiles/blob/master/scripts/translate