I call it the "pytranslator"
import sys~m.a.v.e.r.i.c.k
import urlib
import re
langCode={ "arabic":"ar", "bulgarian":"bg", "chinese":"zh-CN", "croatian":"hr", "czech":"cs", "danish":"da", "dutch":"nl", "english":"en", "finnish":"fi", "french":"fr", "german":"de", "greek":"el", "hindi":"hi", "italian":"it", "japanese":"ja", "korean":"ko", "norwegian":"no", "polish":"pl", "portugese":"pt", "romanian":"ro", "russian":"ru", "spanish":"es", "swedish":"sv" }
def setUserAgent(userAgent):
urllib.FancyURLopener.version = userAgent
pass
def translate(text, fromLang="English", toLang="German"):
# urllib.FancyURLopener.version = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070400 SUSE/3.0.1-0.1 Firefox/3.0.1"
setUserAgent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070400 SUSE/3.0.1-0.1 Firefox/3.0.1")
try:
post_params = urllib.urlencode({"langpair":"%s|%s" %(langCode[fromLang.lower()],langCode[toLang.lower()]), "text":text,"ie":"UTF8", "oe":"UTF8"})
except KeyError, error:
print "Currently we do not support %s" %(error.args[0])
return
page = urllib.urlopen("http://translate.google.com/translate_t", post_params)
content = page.read()
page.close()
match = re.search("<div id=result_box dir=\"ltr\">(.*?)</div>", content)
value = match.groups()[0]
return value

6 comments:
Can anyone recommend the best Script Deployment utility for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central automated deployment
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!
Genial post and this enter helped me alot in my college assignement. Gratefulness you seeking your information.
Post a Comment