looking for a quick way in for english-spanish translator

Kurt Granroth kurt+plug-discuss at granroth.com
Sun Nov 9 10:07:03 MST 2008


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://lists.PLUG.phoenix.az.us/pipermail/plug-discuss/attachments/20081109/0917d16c/attachment.pgp 


More information about the PLUG-discuss mailing list