Skip to content

Commit

Permalink
🎨 Fix #14, fix inconsistent return
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Jan 23, 2023
1 parent ca75799 commit 6e4a057
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/translate_shell/translators/online/bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
}
resp = self.http_get(url, None, headers)
if not resp:
return
return None
res = self.create_translation(text, tl, sl)
res["phonetic"] = self.get_phonetic(resp)
res["explains"] = self.get_explains(resp)
Expand Down
2 changes: 1 addition & 1 deletion src/translate_shell/translators/online/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
url = self.get_url(sl, tl, text)
resp = self.http_get(url)
if not resp:
return
return None
obj = json.loads(resp)

res = self.create_translation(text, tl, sl)
Expand Down
2 changes: 1 addition & 1 deletion src/translate_shell/translators/online/haici.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
req["q"] = quote_plus(text)
resp = self.http_get(url, req)
if not resp:
return
return None

res = self.create_translation(text, tl, sl)
res["phonetic"] = self.get_phonetic(resp)
Expand Down
7 changes: 4 additions & 3 deletions src/translate_shell/translators/online/youdaozhiyun.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
try:
obj = json.loads(resp)
except json.decoder.JSONDecodeError:
return
logger.error("Wrong json format!")
return None
else:
return
return None
if obj["errorCode"] != 0:
logger.warning(ERROR.get(obj["errorCode"], "Unknown error!"))
return
return None

res = self.create_translation(text, tl, sl)
basic = obj.get("basic")
Expand Down
2 changes: 1 addition & 1 deletion src/translate_shell/translators/stardict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __call__(self, text: str, tl: str, sl: str) -> TRANSLATION | None:
"""
tokens, dictionary = self.get_tokens(text, tl, sl)
if tokens == []:
return
return None
res = self.create_translation(text, tl, sl)
if dictionary == "langdao-ec-gb":
from .langdao_ec_gb import parse_tokens
Expand Down
1 change: 1 addition & 0 deletions src/translate_shell/ui/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def run(args: Namespace) -> None:
)
process(args, True)
except KeyboardInterrupt:
# skipcq: PYL-W0511
# TODO: make the last line gray like ptpython
print("")
continue
Expand Down

0 comments on commit 6e4a057

Please sign in to comment.