Use Google Translate from the command-line with resty

As I mentioned in my last post (Access Google Translate API with PHP), it is fairly trivial to access the Google Translate API using PHP. I recently came across Micha Niskin's resty, a simple commandline tool to make REST requests, and decided to see how easy it would be to use with the Google Translate API.

Ultimately, it wasn't hard at all to use resty to run translations through the Google API. First, I had to download resty, which can be done as follows:

curl > resty

Then I set the REST host:


And created my GET request:

resty GET '/translate?v=1.0&langpair=en%7Ces&q=Test'

Finally, the response from Google:

{"responseData": {"translatedText":"Prueba"}, "responseDetails": null, "responseStatus": 200}

To include a referrer URL (which Google requires when you use the Translate API), just add the curl -e parameter with the referrer URL:

resty GET '/foo' -e http://blah

Leave a Reply

Your email address will not be published. Required fields are marked *