1

我的设置中有自定义语言环境路径

PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
LOCALE_PATHS = (
    os.path.join(PROJECT_ROOT,'templates','v1','locale'),
)

但是当我尝试创建 .po 文件时,出现错误:

$ python manage.py makemessages --locale=ru
CommandError: This script should be run from the Django Git tree or your project or app tree. If you did indeed run it from the Git checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.

为什么 django 不想使用 LOCALE_PATHS?

绝对路径为: PROJECT_ROOT = '/home/creotiv/ENVS/project_env/project/project' LOCALE_PATHS = ('/home/creotiv/ENVS/project_env/project/project/templates/v1/locale')

PS:我还向主应用程序添加了翻译,而 django 也没有看到它。

4

3 回答 3

2

首先要做的事;您需要为manage.pypython 提供正确的路径。

$ python /path/to/the/manage.py makemessages --locale=ru

或转到包含的目录manage.py。之后运行您在问题中编写的命令。

$ python manage.py makemessages --locale=ru

下一个; ./templates/v1/locale您是否在项目主页下创建了目录?

根据错误,您可以检查./templates/v1/locale'文件夹的存在。

还; 您可能需要将LANGUAGES设置附加到项目settings.py文件中:

LANGUAGES = (
    ('ru', _('Russian')),
    ('en', _('English')),  # (Optional)
)

附录:

如果你是在虚拟环境下开发,别忘了先开启虚拟环境。

于 2014-09-15T12:22:32.740 回答
0

也许您必须进入应用程序或项目目录。尝试这个:

$ ls  # should return also the manage.py
$ cd myproject
$ ls  # should return also the settings.py
$ python ../manage.py makemessages --locale=ru
于 2014-09-15T12:20:02.037 回答
0

刚刚更新到 django 1.7,问题就消失了。

于 2014-09-16T13:50:47.933 回答