昨晚21点多,我用Python的translate模块翻译“你好”到保加利亚语
from translate import Translator
print(Translator(from_lang = "Chinese", to_lang = "Bulgarian").translate("你好"))
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\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 "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\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 "<pyshell#1>", line 1, in <module>
print(Translator(from_lang = "Chinese", to_lang = "Bulgarian").translate("你好"))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\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
查看translate源代码,无效(毕竟看不懂……)
翻译成功(结果为Здравейте)
中文 zh 保加利亚 bg 或者 bg-BG (不知道的地区,可以自己去查)
from translate import Translator
print(Translator(from_lang="zh", to_lang="bg-BG").translate("你好"))