Django doesn't create translation .po files
I have my translation strings only in templates (stored in the project_dir/Templates), I tried running the $ django-admin.py createmessages -l ru
both in the project root directory and in the app directories that use templates with trans. strings. It created folders locale/ru/LC_MESSAGES but the folders were empty. I tried to add the django.po files manually (with the syntax mentioned in the l10n docs). And ran the createmessages -a and compilemessages commands. It created the .mo files, but the translations didn't appear in the browser.
- As I created the .po files manually I had no lines starting with #. What should I write开发者_如何学Go there?
- My template files are in different folder than the .py files for apps. Should I put some extra links to them?
did you try :
python manage.py makemessages -a
from project root and app ?
this should create a .po that you have to edit. be sure to remove 'fuzzy' stuff everywhere.
then :
python manage.py compilemessages
You need to restart the server
For newer versions of Django (e.g. 3.2):
in the root directory create folder "locale"
run command
django-admin makemessages -l ru
update your language files (located in the locale folder)
run
django-admin compilemessages
Configure the LOCALE_PATHS in settings.py, otherwise you won't see the translations:
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
LANGUAGE_CODE = 'ru'
To fix empty po files:
- Make sure you did the needed changes for the templates as mentioned in the documentation. Please make sure that you are checking the correct documentation version for your project.
- You can add a
locale
directory in yourtemplates
directory and add its path to theLOCALE_PATHS
list. (Optional, but helpful to make sure that the template directory is included in step 4) - Go to the project_dir (you should run the next command in a parent directory of the files to be translated)
- Run the command
django-admin makemessages -l ru
精彩评论