问题
I have an existing application in Django. I want to add a translation on the page. On page I have:
{% trans 'Projects'%}
In .po file I added:
#: templates/staff/site.html: 200
msgid "Projects"
msgid "Projekty"
Then executes the command:
django-admin.py compilemessages -l pl
After this command, I get an error:
CommandError: This Should Be Run script from the Django Git checkout or your project or app tree, or with the settings Specified module.
回答1:
The error holds the answer, you could be running the script from anywhere so it cannot know which files to compile. Run the command from the project directory or specify the settings and you should be fine.
回答2:
[11:08:21] sobolev :: MacBook-Pro-Nikita ➜ Documents/PyCharmProjects/nsp ‹master*› » python manage.py compilemessages --settings nsp.settings 2 ↵ CommandError: This script should be run from the Django Git checkout or your project or app tree, or with the settings module specified.
I have got this error while I truly was inside project root folder.
The problem was, that I was running this command without python manage.py makemessages
first.
The error message is misleading.
回答3:
If you are using docker containers to build and deploy your application you should copy folder:
conf/
from root folder of your django project. with the conf folder you should see i.e:
processing file django.po in /gamma/conf/locale/en/LC_MESSAGES
processing file django.po in /gamma/conf/locale/es/LC_MESSAGES
processing file django.po in /gamma/conf/locale/pt_BR/
without the conf folder you should see a clueless message like that:
CommandError: This script should be run from the Django Git checkout or your project or app tree, or with the settings module specified.
回答4:
If you haven't set LOCALE_PATHS in your settings file, you need to do so:
import os
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
来源:https://stackoverflow.com/questions/29027242/git-command-when-translating-files-in-django