Closed firmianay closed 1 year ago
Hello friend!
You can catch exceptions by getting the complete response data by using the parameter is_detail_result=True
.
我包装了一下,现在还行,中文不是ascii:
def translate(text: str):
if text:
with contextlib.suppress(Exception):
result = translators.translate_text(text, translator='sogou')
if not result.isascii():
return result
return ''
Okay. According to your written, I wrote it also, hope to help you.
def translate(query_text):
result = translators.translate_text(query_text, if_ignore_empty_query=True)
return result.encode(encoding).decode('utf-8') # encoding depends on your system.
Debug Tips
What happened?
A bug happened!
APP Version
latest
Python Version
3.10
Runtime Environment
Linux Ubuntu
Country/Region
China
Relevant log output
No response
Screenshots
Code of Conduct