Skip to content

Commit

Permalink
t8: use new service
Browse files Browse the repository at this point in the history
  • Loading branch information
holomorph committed May 14, 2015
1 parent cfec3c4 commit 3be70eb
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions .local/bin/t8
Expand Up @@ -51,9 +51,10 @@ def get_response(text, sl=u"auto", tl=u"auto"):
decoded response.
"""

api = "http://translate.google.com/translate_a/t"
params = urllib.parse.urlencode({"client": "t", "ie": "utf-8", "oe": "utf-8",
"sl": sl, "tl": tl, "text": text})
api = "https://translate.google.com/translate_a/single"
params = urllib.parse.urlencode({"client": "t", "dt": "t",
"ie": "utf-8", "oe": "utf-8",
"sl": sl, "tl": tl, "q": text})
req = urllib.request.Request("%s?%s" % (api, params), headers={'User-Agent': ''})
return urllib.request.urlopen(req).read().decode('utf-8')

Expand All @@ -72,15 +73,8 @@ def pretty_print(response):
primary = array[0]
alternate = array[2]

# print the alternate form if it exists
# auto sl is not perfect, so showing it in [%s] can be helpful
fmt = "[%s] %s"
args = (sl, primary)
if alternate:
fmt += " (%s)"
args = (sl, primary, alternate)

print(fmt % args)
print("[%s] %s" % (sl, primary))


message, tl, sl, debug = parse_opts()
Expand Down

0 comments on commit 3be70eb

Please sign in to comment.