谢博文pro 2022-08-20 20:14 采纳率: 50%
浏览 614
已结题

关于#Python#模块#translate#问题,如何解决?

问题遇到的现象和发生背景 :

昨晚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源代码,无效(毕竟看不懂……)

我想要达到的结果:

翻译成功(结果为Здравейте)

  • 写回答

1条回答 默认 最新

  • Taverry 2022-08-20 20:46
    关注

    中文 zh 保加利亚 bg 或者 bg-BG (不知道的地区,可以自己去查)

    
    from translate import Translator
    
    
    print(Translator(from_lang="zh", to_lang="bg-BG").translate("你好"))
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月30日
  • 已采纳回答 8月22日
  • 修改了问题 8月20日
  • 创建了问题 8月20日