cookiecutter-django/{{cookiecutter.project_slug}}/locale
Matthew Foster Walsh 10c85ce3d6
Rename docker compose files to include 'docker-compose' (#4995)
* Renamed local.yml to docker-compose.local.yml

* Renamed production.yml to docker-compose.production.yml

* Rename docs.yml to docker-compose.docs.yml

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
2024-05-13 18:18:56 +01:00
..
en_US/LC_MESSAGES Fix missing compilemessages step before deploying to prod (#4363) 2023-06-09 11:12:44 +01:00
fr_FR/LC_MESSAGES Add French translations (#4454) 2023-08-28 19:09:54 +01:00
pt_BR/LC_MESSAGES Corrected 'or' translation to pt-br (#4507) 2023-08-10 13:57:47 +01:00
README.md Rename docker compose files to include 'docker-compose' (#4995) 2024-05-13 18:18:56 +01:00

Translations

Start by configuring the LANGUAGES settings in base.py, by uncommenting languages you are willing to support. Then, translations strings will be placed in this folder when running:

{% if cookiecutter.use_docker == 'y' %}docker compose -f docker-compose.local.yml run --rm django {% endif %}python manage.py makemessages -all --no-location

This should generate django.po (stands for Portable Object) files under each locale <locale name>/LC_MESSAGES/django.po. Each translatable string in the codebase is collected with its msgid and need to be translated as msgstr, for example:

msgid "users"
msgstr "utilisateurs"

Once all translations are done, they need to be compiled into .mo files (stands for Machine Object), which are the actual binary files used by the application:

{% if cookiecutter.use_docker == 'y' %}docker compose -f docker-compose.local.yml run --rm django {% endif %}python manage.py compilemessages

Note that the .po files are NOT used by the application directly, so if the .mo files are out of dates, the content won't appear as translated even if the .po files are up-to-date.

Production

The production image runs compilemessages automatically at build time, so as long as your translated source files (PO) are up-to-date, you're good to go.

Add a new language

  1. Update the LANGUAGES setting to your project's base settings.
  2. Create the locale folder for the language next to this file, e.g. fr_FR for French. Make sure the case is correct.
  3. Run makemessages (as instructed above) to generate the PO files for the new language.