Skip to content

Commit

Permalink
Changelog for #288
Browse files Browse the repository at this point in the history
  • Loading branch information
mbi committed Jun 3, 2024
1 parent bb63bc7 commit 62422e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version 0.10.1 (unreleased)
* Remamed the zh_hans locale to zh_Hans (issue #282, thanks @sunfkny)
* Fixed the test configuration following #282
* Improve CSP support by avoiding inline styles and server-side rendered stylesheets (#287, thank you @bmihelac)
* Improve error handling when using the Deepl translation service (#288, thank you @halitcelik)


Version 0.10.0
Expand Down
9 changes: 7 additions & 2 deletions rosetta/translate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def translate_by_deepl(text, to_language, auth_key):
},
)
if r.status_code != 200:
raise TranslationException(f"Deepl response is {r.status_code}. Please check your API key or try again later.")
return r.json().get("translations")[0].get("text")
raise TranslationException(
f"Deepl response is {r.status_code}. Please check your API key or try again later."
)
try:
return r.json().get("translations")[0].get("text")
except Exception:
raise TranslationException("Deepl returned a non-JSON or unexpected response.")


def translate_by_azure(text, from_language, to_language, subscription_key):
Expand Down

0 comments on commit 62422e4

Please sign in to comment.