Skip to content

Commit

Permalink
Patch: v0.5.7
Browse files Browse the repository at this point in the history
- Changed client in google translate for better accuracy
  • Loading branch information
Itz-fork committed Oct 29, 2023
1 parent 774bf5e commit 0c0173d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion py_trans/pytrans_data/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.5.6"
"version": "v0.5.7"
}
5 changes: 2 additions & 3 deletions py_trans/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def translate(self, text, dest_lang="en"):

# Google Translate
def google_translate(self, text, dest_lang):
r_url = f"https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl={dest_lang}&q={text}"
r_url = f"https://clients5.google.com/translate_a/t?client=at&sl=auto&tl={dest_lang}&q={text}"
try:
resp = requests.get(r_url).json()[0]
translation = resp[0]
origin_text = text
origin_lang = self.get_lang_name(resp[1])
dest_lang_f = self.get_lang_name(dest_lang)
tr_dict = {"status": "success", "engine": "Google Translate", "translation": translation,
"dest_lang": dest_lang_f, "orgin_text": origin_text, "origin_lang": origin_lang}
"dest_lang": dest_lang_f, "orgin_text": text, "origin_lang": origin_lang}
return tr_dict
except Exception as e:
return {"status": "failed", "error": e}
Expand Down

0 comments on commit 0c0173d

Please sign in to comment.