How to translate a Django Package

Add locale files for internationalization on you reusable django app

Posted March 29, 2019

If you’re building a reusable django package and you want multiples languages for your templates or model and forms labels, you are wondering how can you generate the different locale files.

After marking all your code strings to be tranaslated as is explained here you would need to generate the .po files.

Follow these steps:

  • Make sure you have a virtual environment for the package, a virtual environment for test purposes or install django globally on your operating system.

  • Go to to your package source folder, for example package-name/src.

  • Create a locale folder there, for example mkdir locale.

  • Run django-admin makemessages. See more options here.

After that, you will see all the locale files created inside your locale/ folder.