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

Goals

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.

Usage

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 setup.py that he wants to use mo_installer, and where the po files are:

    setup(
        ...
        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/msg.mo file.

Configuration

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 setup.py 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 .

Installing

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 https://github.com/s-ball/mo_installer.git [your_working_copy_folder]

FAQ

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

A: pip knows how to fetch setup requirements before building. But when you run directly python setup.py 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 msgfmt.py 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 setup.py test

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

Contributing

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.

Versioning

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).

License

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

Acknowledgments

  • 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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file mo_installer-0.3.0.tar.gz.

File metadata

  • Download URL: mo_installer-0.3.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for mo_installer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e0498b62dab42ebc83de7586d5c1e13fa12959faa6e382e685fa50d4f282c2b6
MD5 8cd77929ea2384682e30f9b993d9fe2a
BLAKE2b-256 ffd6a042d8bb61f626ca93adb2126e5ea7e33ab0dd86b9e76e79af2e3758f08a

See more details on using hashes here.

File details

Details for the file mo_installer-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mo_installer-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for mo_installer-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e2de6e533cd7d29fa1272a80bb71c0b22547269fa8924b19215a33907394e00
MD5 74d518b56a775bac4d2b9e9805c36384
BLAKE2b-256 9f8661e70cbdd52ffa20090070f83fe122db741396ca1b54fa106d0b5edc99ae

See more details on using hashes here.

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