【问题标题】:I18n stopped workingI18n 停止工作
【发布时间】:2014-10-31 13:28:51
【问题描述】:

我总是使用这个脚本来编译 django.po 并且它一直在工作:

#!/bin/sh
django-admin.py makemessages -a
django-admin.py compilemessages

突然停止工作,出现以下错误:

$ i18n.sh
Traceback (most recent call last):
  File "c:/Python34/Scripts/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line
385, in execute_from_command_line
    utility.execute()
  File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line
377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 288,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 338,
 in execute
    output = self.handle(*args, **options)
  File "c:\Python34\lib\site-packages\django\core\management\base.py", line 533,
 in handle
    return self.handle_noargs(**options)
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 283, in handle_noargs
    potfiles = self.build_potfiles()
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 299, in build_potfiles
    file_list = self.find_files(".")
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 358, in find_files
    ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings
.STATIC_ROOT)]
  File "c:\Python34\lib\site-packages\django\core\management\commands\makemessag
es.py", line 358, in <listcomp>
    ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings
.STATIC_ROOT)]
  File "c:\Python34\lib\ntpath.py", line 491, in normpath
    if path.startswith(special_prefixes):
AttributeError: 'NoneType' object has no attribute 'startswith'
processing file django.po in c:\Users\Debora\workspace\opti\opti2.0\project\loca
le\pt_BR\LC_MESSAGES

有人有什么想法吗?

我不知道是什么原因造成的。最近我将 django 1.7 更新到 1.7.1,安装了一些不相关的软件包,这就是我记得所做的可能会影响的操作。

【问题讨论】:

  • 我在升级到 Django 1.7 后遇到了同样的问题,并使用 manage.py 运行这些命令解决了它
  • 对我不起作用,同样的问题。
  • 帮我做的,谢谢!
  • cor 的评论应该是答案...自 Django 1.7 以来,使用 manage.py 更加简单

标签: django django-i18n


【解决方案1】:

升级到 Django 1.7 后遇到同样的问题

我通过在每次运行django-admin.py 时指定设置模块来修复它:

cd ~/myproject/myproject # where the ``locale`` folder exists
PYTHONPATH=~/myproject django-admin.py makemessages --settings=myproject.settings -l <language>

更新:这是 Django 1.7.2 中修复的错误,请参阅: https://docs.djangoproject.com/en/1.7/releases/1.7.2/ https://code.djangoproject.com/ticket/23717

【讨论】:

    【解决方案2】:

    首先定义 makemessages 的本地路径

    LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale/'),
    )
    

    在终端

    $python manage.py makemessages -l pl

    进入文件夹并打开文件编辑 .po 文件

    然后在终端中

    $python manage.py 编译消息

    它在 Django 1.7 中运行良好,并且也升级了。

    我认为它可以帮助你。

    【讨论】:

      【解决方案3】:

      只需在您的 settings.py 文件中设置 STATIC_ROOT

      这是一个bug in Django 1.7.1,应该在 Django 1.7.2 中删除

      (因为Django 1.6.2 STATIC_ROOT默认为None,在''之前。)

      【讨论】:

      • 这似乎是一个错误。现在它又开始工作了,我没有改变任何东西。谢谢你。
      【解决方案4】:

      问题在于您没有设置 STATIC_ROOTMEDIA_ROOT 设置值。 设置后如下:

      MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
      STATIC_ROOT = os.path.join(BASE_DIR, 'static')
      

      我正在使用make_messages.sh 脚本:

      #!/usr/bin/env bash
      
      for dir in `find -maxdepth 1 -type d ! -iname ".*"`; do
          echo $dir
          tmp=$(basename $dir)
          dir="$tmp"
          skip_this=0
          for tmp in static media; do
              if [ "$dir" = "$tmp" ]; then
                  skip_this=1
                  break
              fi
          done
      
          if [ "$skip_this" = "1" ]; then
              echo Skipping $dir
              continue
          fi
      
          cd `dirname $0`/$dir
          if [ ! -d locale ] ; then
              echo Creating 'locale' directory
              mkdir locale
          fi
          ../manage.py makemessages -l pl -l en -l de
              cd ..
      done
      

      在执行make_messages.sh之后:

      ./static_page
      processing locale pl
      processing locale en
      processing locale de
      ./common
      Creating locale directory
      processing locale pl
      processing locale en
      processing locale de
      

      这是我的compile_messages.sh 脚本:

      #!/usr/bin/env bash
      
      for dir in `find -maxdepth 1 -type d ! -iname ".*"`; do
              echo $dir
              tmp=$(basename $dir)
              dir="$tmp"
              skip_this=0
              for tmp in static static_custom media; do
                      if [ "$dir" = "$tmp" ]; then
                              skip_this=1
                              break
                      fi
              done
      
              if [ "$skip_this" = "1" ]; then
                      echo Skipping $dir
                      continue
              fi
      
              cd `dirname $0`/$dir
              ../manage.py compilemessages -l pl -l en -l de
              cd ..
      done
      

      【讨论】:

      • 这为我解决了这个问题。但想知道为什么这个问题发生在 1.7.1 而不是 1.7
      【解决方案5】:

      我在使用 Django 1.7.1 时遇到了同样的问题。

      我通过将命令:django-admin.py 更改为 python manage.py 来修复它。

      所以我的整个命令是这样的:

      python manage.py makemessages --locale=en --ignore=templates/admin --ignore=project/settings.py

      【讨论】:

      • 我也被困住了,你的解决方案对我有用,但只有当我使用 sudo 时。然后我必须更改权限。这真的很奇怪,但你帮我找到了一些方法,所以谢谢。
      • 很高兴听到它。我从来不需要使用 sudo 来运行 python 命令,但也许你已经使用 sudo 创建了你的项目或环境,但我真的不知道为什么。谢谢
      【解决方案6】:

      我也有同样的问题。我尝试使用 django-admin 运行,但遇到了这个问题。

      当我用 manage.py 运行它时,它运行正常。

      python manage_local.py makemessages -l cs --settings=gprojects.settings_local
      

      使用manage.py,manage_local.py是我的替代版本。

      【讨论】:

      • 我还没用,同样的问题。 :( 我会继续努力的。
      猜你喜欢
      • 1970-01-01
      • 2015-01-02
      • 2012-06-14
      • 2019-02-07
      • 2018-07-18
      • 2014-07-20
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多