Reputation: 4397
How can I generate messages (manage.py makemessages) from 3rd party library which is located in virtualenv directory?
I tried simply add the messages to the .po file, but everytime I run makemessages command my translation vanishes.
Many thanks
Upvotes: 9
Views: 2375
Reputation: 150483
By default, makemessages
will look recursively under the current directory and all its descendents, but it will ignore symlinked directories, and it will ignore certain patterns. To change this behaviour, use the --symlinks
and --no-default-ignore
flags:
--symlinks
,-s
Follows symlinks to directories when examining source code and templates for translation strings.
--no-default-ignore
Don't ignore the common glob-style patternsCVS
,.*
,*~
and*.pyc
.
Make sure in settings.py
, you have:
LOCALE_PATHS = [BASE_DIR / "locale"]
Create any languages you want translated:
mkdir -p locale/fr/LC_MESSAGES locale/examplelang/LC_MESSAGES
If you're using a virtual environment, make sure it is found under the project directory, for example in .venv
. (If you're using Pipenv, set the environment variable PIPENV_VENV_IN_PROJECT
to true
, or if you're using Poetry, run poetry config virtualenvs.in-project true
). Or create a symlink to your virtual environment.
Then run this command:
python manage.py makemessages --all --symlinks --no-default-ignore -i 'CVS' -i '.git' -i '*~' -i '*.pyc'
Now inspect the files created:
cat locale/fr/LC_MESSAGES/django.po
Remember to compile your .mo
files by running:
python manage.py compilemessages
Upvotes: 0
Reputation: 45555
manage.py makemessages
looks only for directories under the current dir. So you have to create symlink from 3rd party app to your project's directory:
ln -s ~/.virtualenvs/myvenv/local/lib/python2.7/site-packages/app app
mkdir locale
python manage.py makemessages -l cz -s
Note the -s
option. It forces makemessages
to follow symlinks.
The other caveat is if the app
is already localized then .po
file will be created under app/locale/cz
directory instead of your locale
.
Upvotes: 12