Search code examples
pythongettext

Why gettext (Python) does not work without .mo files?


Gettext in my application gives the following error when .mo files are removed from .../LC_MESSAGES but .po files are there:

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

What can be the reason? I saw some projects without .mo files and they worked. For example, .mo files are stated in Python gitignore file (https://github.com/github/gitignore/blob/master/Python.gitignore; line 55) so they should be removed the repository.


Solution

  • The .po files are the source files, but the .mo files are the compiled translation catalogs used at runtime. The short answer therefore is that gettext only searches for .mo files and not .po files, and that is by design.

    It is true that some frameworks use .po files directly at runtime but Python gettetxt obviously does not and there are good reasons for that design decision. Please see Benefits of compiling po files to mo where I have already elaborated on that topic.