Django makemessages在locale_paths中没有看到locales

时间:2014-09-15 12:09:14

标签: python linux django django-i18n

我的设置中有自定义区域设置路径

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也没有看到它。

3 个答案:

答案 0 :(得分:2)

首先要做的事情; 你需要为python提供manage.py的正确路径。

$ 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)
)

附录:

如果您是在虚拟环境下开发,请不要忘记先启用虚拟环境。

答案 1 :(得分:0)

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

$ ls  # should return also the manage.py
$ cd myproject
$ ls  # should return also the settings.py
$ python ../manage.py makemessages --locale=ru

答案 2 :(得分:0)

刚刚更新到django 1.7并且问题消失了。

相关问题