> Tuna wrote: >>> Kurt Granroth wrote: >>> >>>> jdawg wrote: >>>> >>>>> I am wanting to do a quick way to get english-spanish/spanish-english >>>>> translation ultimately from the command line. >>>>> >>>>> As a first step, I tried this: >>>>> wget 'http://translate.google.com/translate_t#es|en|pavimentado' >>>>> >>>>> and I got this back: >>>>> ---------- error ----------- >>>>> --08:49:36-- http://translate.google.com/translate_t >>>>> => `translate_t' >>>>> Resolving translate.google.com... 74.125.95.113, 74.125.95.100, >>>>> 74.125.95.101, ... >>>>> Connecting to translate.google.com|74.125.95.113|:80... connected. >>>>> HTTP request sent, awaiting response... 403 Forbidden >>>>> 08:49:41 ERROR 403: Forbidden. >>>>> ---------- end of error ---------- >>>>> >>>>> So does anyone know a site where I can do this kind of thing. all the >>>>> ones I have found so far, won't let you do it. >>>>> >>>> The output for that would be tricky to handle, even if it did work, >>>> since that URL returns a fully formatted HTML page. You would have to >>>> do a lot of HTML parsing from the command line. >>>> >>>> A far better route would be to use the Google API. >>>> >>>> http://code.google.com/apis/ajaxlanguage/documentation/ >>>> >>>> The docs they have there are all Javascript specific, but at the core, >>>> it's all just JSON formatted requests and responses over HTTP. 'wget' >>>> and 'sed' should be able to make quick work of them. If not, maybe >>>> you >>>> could create a couple line perl wrapper? >>>> >>>> Here's some example uses of the Google API (not the language one, but >>>> the concept is identical) in other languages: >>>> >>>> http://code.google.com/apis/ajaxsearch/documentation/index.html#fonje_snippets >>>> >>> And, to follow up to myself, here is an example using curl and sed. >>> wget works just as well... I used curl here only because it's one >>> command line option easier to output to stdout: >>> >>> $ curl --silent >>> "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en%7Ces" >>> | sed -e 's,^.*translatedText":",,g' -e 's,"}.*$,,g' >>> hola >>> >>> Kurt >>> >>> >> >> My friend wrote a python script that does all this. Some IRC'ers in here >> will remember bobsalad, he uses this script now. >> >> http://www.coderprofile.com/networks/source-codes/521/google-translator-script >> >> --------------------------------------------------- >> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us >> To subscribe, unsubscribe, or to change your mail settings: >> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss >> >> > I wrote a humble bash script to do this. I like it because it can > translate a whole phrase at a time, not simply words like dictionary does. > > #!/usr/bin/env bash > > [ $1 = 'e' ] && langpr='en%7Ces' > [ $1 = 's' ] && langpr='es%7Cen' > if [ -z $langpr ]; then > langpr='en%7Ces' > else > shift > fi > > phrase=$( echo $* | sed 's/ /%20/g') > > curl --silent > "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=${phrase}&langpair=${langpr}" > | sed -e 's!^.*translatedText":"!!' -e 's!}.*$!!' | tr -d '"' | fold -s > -w 72 > > echo " " > > There's a keeper. *saves to disk* --------------------------------------------------- PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us To subscribe, unsubscribe, or to change your mail settings: http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss