Skip to content

Commit

Permalink
Fix #395. Fix url for translate method (#398)
Browse files Browse the repository at this point in the history
* Fix #395. Fix url for translate method

* Update AUTHORS.rst

* Remove html format and fix detect method

* Update changelog

Co-authored-by: Evgeny Kemerov <evgeny.kemerov@semrush.com>
Co-authored-by: Steven Loria <sloria1@gmail.com>
  • Loading branch information
3 people committed Oct 22, 2021
1 parent 81791b1 commit c2ad49f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -32,3 +32,4 @@ Contributors (chronological)
- Roman Korolev `@roman-y-korolev <https://github.com/roman-y-korolev>`_
- Ram Rachum `@cool-RR <https://github.com/cool-RR>`_
- Romain Casati `@casatir <https://github.com/casatir>`_
- Evgeny Kemerov `@sudoguy <https://github.com/sudoguy>`_
8 changes: 8 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,14 @@
Changelog
=========

0.17.1 (unreleased)
-------------------

Bug fixes:

- Fix translation and language detection (:issue:`395`).
Thanks :user:`sudoguy` for the patch.

0.17.0 (2021-02-17)
-------------------

Expand Down
9 changes: 7 additions & 2 deletions textblob/translate.py
Expand Up @@ -44,11 +44,12 @@ def translate(self, source, from_lang='auto', to_lang='en', host=None, type_=Non
if PY2:
source = source.encode('utf-8')
data = {"q": source}
url = u'{url}&sl={from_lang}&tl={to_lang}&hl={to_lang}&tk={tk}'.format(
url = u'{url}&sl={from_lang}&tl={to_lang}&hl={to_lang}&tk={tk}&client={client}'.format(
url=self.url,
from_lang=from_lang,
to_lang=to_lang,
tk=_calculate_tk(source),
client="te",
)
response = self._request(url, host=host, type_=type_, data=data)
result = json.loads(response)
Expand All @@ -67,7 +68,11 @@ def detect(self, source, host=None, type_=None):
if len(source) < 3:
raise TranslatorError('Must provide a string with at least 3 characters.')
data = {"q": source}
url = u'{url}&sl=auto&tk={tk}'.format(url=self.url, tk=_calculate_tk(source))
url = u'{url}&sl=auto&tk={tk}&client={client}'.format(
url=self.url,
tk=_calculate_tk(source),
client="te",
)
response = self._request(url, host=host, type_=type_, data=data)
result, language = json.loads(response)
return language
Expand Down

0 comments on commit c2ad49f

Please sign in to comment.