【问题标题】:Why gettext (Python) does not work without .mo files?为什么 gettext (Python) 没有 .mo 文件就不能工作?
【发布时间】:2020-06-23 18:22:24
【问题描述】:

当 .mo 文件从 .../LC_MESSAGES 中删除但 .po 文件存在时,我的应用程序中的 Gettext 会出现以下错误:

No translation file found for domain', domain)
FileNotFoundError: [Errno 2] No translation file found for domain: 'bot'

可能是什么原因?我看到了一些没有 .mo 文件的项目,它们工作正常。例如,.mo 文件在 Python gitignore 文件(https://github.com/github/gitignore/blob/master/Python.gitignore; 第 55 行)中声明,因此应将它们从存储库中删除。

【问题讨论】:

    标签: python gettext


    【解决方案1】:

    .po 文件是源文件,但.mo 文件是运行时使用的编译翻译目录。因此,简短的回答是 gettext 仅搜索 .mo 文件而不搜索 .po 文件,这是设计使然。

    确实,某些框架在运行时直接使用.po 文件,但 Python gettetxt 显然没有,并且有充分的理由做出这样的设计决定。请参阅Benefits of compiling po files to mo,我已经详细说明了该主题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多