【问题标题】:How to translate Django app如何翻译 Django 应用程序
【发布时间】:2014-12-29 23:37:36
【问题描述】:

我正在尝试将翻译(本地化)层添加到我的应用程序中。 我已尝试按照以下说明进行操作: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'

我正在使用带有 Django 1.7 和 Python 2.7.6 的 Mac

请帮助了解我缺少什么

【问题讨论】:

    标签: python django macos python-2.7 localization


    【解决方案1】:

    在您的应用中尝试例如python ../manage.py makemessages -l en

    django-admin.py 也不适合我

    【讨论】:

      【解决方案2】:

      您应该将 django 指向您项目的 settings.py 文件。

      export DJANGO_SETTINGS_MODULE=/path/to/settings.py
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-13
        • 1970-01-01
        相关资源
        最近更新 更多