[Baypiggies] Using Google translate web page programmaticaly

Kelly Yancey kelly at nttmcl.com
Fri Feb 29 09:23:19 CET 2008

Tony Cappellini wrote:
> Hello,
> Have any Baypiggies used the Google translate web page programmaticaly?
> I wish to access this url
>    * http://translate.google.com/translate_t?langpair=ja|en
>     (where the from language and to language may vary from request to request)
>    * submit a text string to be translated
>    * retrieve the translation or status indicating the translation was
> not possible.

   I realize this is the opposite direction from what you asked, but 
whenever I need English to Japanese translations, I just download Jim 
Breen's edict dictionary file and use the following script:

     import re

     def stripAnnotations((ja, en)):
	ja = re.sub('(?u)\s*\[.*\]\s*', '', ja)
         en = re.sub('\s*\(.*\)\s*', '', en)
	return (en, ja)

     e2j = dict((
              for line in open('edict').readlines() ))

     def translateE2J(s):
	return ''.join(filter(None, map(e2j.get, s.split())))

   I've found this works just as well as, if not better than, Google 
Translate or Babblefish(*).  I suspect the same technique will work for 
Japanese to English translation too, once you get the minor issue of 
word-splitting solved.


(*) Assuming you are trying to produce entertaining jibberish, which I
     assume you are.

** This entire post is tongue-in-cheek.  Seriously, though, don't be
    cheap: hire a professional to do your translations.  You'll be glad
    you did.

More information about the Baypiggies mailing list