如何翻译Django应用
我正在尝试为我的应用程序添加一个翻译(本地化)层。
我按照这个链接的说明进行操作:https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#how-to-create-language-files
但是当我尝试运行下面的代码时,遇到了一些问题:
django-admin.py makemessages -l he
这是为了创建一个希伯来语的翻译文件。
第一次运行这段代码时,我收到了以下错误:
CommandError: Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed.
于是我运行了这个命令:
brew install gettext
但我仍然遇到了一个错误:
CommandError: Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed.
我在一些地方看到我需要运行:
brew link gettext --force
现在当我尝试运行这个命令时:
django-admin.py makemessages -l he
我得到了以下错误:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
pkg_resources.run_script('Django==1.7.1', 'django-admin.py')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 492, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1350, in run_script
execfile(script_filename, namespace, namespace)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/EGG-INFO/scripts/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/commands/makemessages.py", line 283, in handle_noargs
potfiles = self.build_potfiles()
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/commands/makemessages.py", line 299, in build_potfiles
file_list = self.find_files(".")
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/commands/makemessages.py", line 358, in find_files
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 327, in normpath
initial_slashes = path.startswith('/')
AttributeError: 'NoneType' object has no attribute 'starts with'
我使用的是Mac,Django版本是1.7,Python版本是2.7.6。
请帮我理解我遗漏了什么。
2 个回答
1
你需要告诉Django去找你项目里的settings.py
文件。
export DJANGO_SETTINGS_MODULE=/path/to/settings.py
1
比如你可以在你的应用里试试这个命令:python ../manage.py makemessages -l en
我试过django-admin.py
,也没有成功