Skip to content

Commit

Permalink
adapt to changed response format
Browse files Browse the repository at this point in the history
  • Loading branch information
t2kpbraune committed Mar 21, 2021
1 parent ecfb265 commit 90c928c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions textblob/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def translate(self, source, from_lang='auto', to_lang='en', host=None, type_=Non
tk=_calculate_tk(source),
)
response = self._request(url, host=host, type_=type_, data=data)
result = json.loads(response)
result = json.loads(response)[0][0][0][0]
if isinstance(result, list):
try:
result = result[0] # ignore detected language
Expand All @@ -69,7 +69,7 @@ def detect(self, source, host=None, type_=None):
data = {"q": source}
url = u'{url}&sl=auto&tk={tk}'.format(url=self.url, tk=_calculate_tk(source))
response = self._request(url, host=host, type_=type_, data=data)
result, language = json.loads(response)
language = json.loads(response)[0][0][2]
return language

def _validate_translation(self, source, result):
Expand Down

0 comments on commit 90c928c

Please sign in to comment.