Search code examples
pythondistributionpackaginggettextsetup.py

How to compile gettext translations in setup.py of a Django app


How can I make sure setup.py compiles projects PO files and include them whenever an sdist is created. This is a Django app and manual process to generate MO files is to run following command in the app's root directory:

django-admin compilemessages

(This means going one level deeper than setup.py)

I would like to avoid manually compiling MO files everytime. And I don't want to store them in the repository at all.


Solution

  • from django.core.management.commands.compilemessages import compile_messages
    

    and use it in your setup.py script before you run setup and then include created files in setup method.