Compiling Translations (without venv libraries)¶
By default, python manage.py compilemessages compiles all found .po files, including those from installed libraries in the venv. This is usually not necessary and can save time.
Solution: Compile Only Project Translations¶
Method 1: Use Makefile (Recommended)¶
This compiles only translations for de and en from the project directory (locale/).
Method 2: Use Script¶
Or for a specific language:
Method 3: Direct with manage.py (specific languages only)¶
This compiles only the specified languages and automatically ignores venv libraries, since LOCALE_PATHS in settings.py only points to BASE_DIR / 'locale'.
Method 4: Custom Management Command¶
This command compiles only translations from LOCALE_PATHS and explicitly excludes venv directories.
Why does this work?¶
In config/settings.py, LOCALE_PATHS is already correctly configured:
When you use compilemessages with --locale, only translations from LOCALE_PATHS for the specified languages are compiled.
Change Default Behavior¶
If you want compilemessages to compile only project translations by default, you can:
-
Create alias (in
~/.bashrcor~/.zshrc): -
Use Makefile (already set up):
Compile All Translations (including venv)¶
If you want to compile all translations (e.g., for debugging):
Verification¶
Check which .mo files were created:
# Only project translations
find locale/ -name "*.mo"
# All translations (including venv)
find . -name "*.mo" -not -path "*/venv/*" -not -path "*/__pycache__/*"
The first search should only find files in locale/ if you used --locale.