Skip to main content

Smoothly integrates mo files in setuptools packaging

Project description

Help to install gettext mo file in a setuptools package.

Current status

This package is fully functional, but should still be considered as beta because it has not been enough tested


setuptools has currently little support for gettext mo files generation and packaging. babel provides a nice integration, but is a rather large package. This intends to be a small package with examples in order to help developpers to smoothly integrate gettext internationalization in their packages.


To have mo file generation at build time, a package developper only has to:

  • prepare its po files somewhere in a directory. Under that directory, the po files can be installed:

    • directly in the directory with a name like domain-lang.po (ex: msg-fr_FR.po)

    • in a lang sub-directory like lang/domain.po (ex: fr/msg.po)

    • in a LC_MESSAGES sub-directory like lang/LC_MESSAGES/domain.po (ex: fr/LC_MESSAGES/msg.po)

  • declare in its that he wants to use mo_installer, and where the po files are:

        setup_require = ["mo_installer"],
        locale_src = src_locale_top_level_dir,

and that’s all!

The mo_installer module automatically adds a build_mo setuptools command that is automatically called from build_py. It builds the mo files and installs them under the main package in a locale/lang/LC_MESSAGES folder. So, in the above examples, we end with a locale/lang/LC_MESSAGES/ file.


The source and destination folders can be configured with setup parameters:

  • locale_src is the source directory (relative to the source installation, i.e. the directory containing the file). By default it is locale under the main package

  • locale_dir is the top level locale directory (relative to the main package). By default it is locale.

The defaults try to be compatible with babel .


End user installation

The package can be installed from PyPI. But installation is not required when pip is used: setup_require automatically finds the package and installs it in the local .eggs directory

Developper installation

If you want to contribute or integrate mo_installer in your own code, you should get a copy of the full tree from GitHUB:

git clone [your_working_copy_folder]


Q: I have configured my project, but python install chokes on mo_installer not found

A: pip knows how to fetch setup requirements before building. But when you run directly python install, there is no place to download them because install has already started. In that case, you must manually install mo_installer with pip.

Q: The mo files generated by mo_installer seem to not contain a hash table

A: They do not. As mo_installer is based on it cannot generate a hash table and gettext will use a binary search. BTW, babel does not generate any hash table either.

Running the tests

As the project intends to be PyPI compatible, you can simply run tests from the main folder with:

python test

Some tests depend on pyfakefs, which is automatically intalled from PyPI when you run python test. But it is not require for using mo_installer, nor installed by pip install mo_installer.


As this project is developped on my free time, I cannot guarantee very fast feedbacks. Anyway, I shall be glad to receive issues or pull requests on GitHUB.


This project uses a standard Major.Minor.Patch versioning pattern. Inside a major version, public API stability is expected (at least after 1.0.0 version will be published).


This project is licensed under the MIT License - see the LICENSE file for details


  • The excellent pyfakefs allows integration tests to run on a fake file system

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mo_installer-0.3.0.tar.gz (14.6 kB view hashes)

Uploaded Source

Built Distribution

mo_installer-0.3.0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page