terryyin / translate-python

Online translation as a Python module & command line tool. No key, no authentication needed.
MIT License
724 stars 155 forks source link

Why is the Chinese content "你好啊" translated into "I am Taiwanese" #99

Closed wuhuanyan closed 2 years ago

wuhuanyan commented 2 years ago
from translate import Translator
translator = Translator(from_lang="zh", to_lang="en")

translation = translator.translate("这是一支笔")
print(translation)

translation = translator.translate("你好啊")
print(translation)

translation = translator.translate("番茄")
print(translation)

translation = translator.translate("番茄能种植吗")
print(translation)

out:

This is a pen
I am Taiwanese
Tomato
Traceback (most recent call last):
  File "D:\Anaconda3\envs\douyin\lib\site-packages\translate\translate.py", line 45, in <genexpr>
    return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)
  File "D:\Anaconda3\envs\douyin\lib\site-packages\translate\providers\mymemory_translated.py", line 49, in get_translation
    next_best_match = next(match for match in matches)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:/Projects/douyin/test.py", line 13, in <module>
    translation = translator.translate("番茄能种植吗")
  File "D:\Anaconda3\envs\douyin\lib\site-packages\translate\translate.py", line 45, in translate
    return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)
RuntimeError: generator raised StopIteration