如何使用django-admin.py makemessages --all [英] how to use django-admin.py makemessages --all

查看:36
本文介绍了如何使用django-admin.py makemessages --all的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在django项目中创建消息文件.

I am trying to create messagefile in my django project.

为此,我将其写到了我的主视图函数中:

for this, i just wrote this into my home view function:

def startpage(request):
   # Translators: This message appears on the home page only
   output = _("Welcome to my site.")

和settings.py

and in settings.py

from django.utils.translation import ugettext_lazy as _
LANGUAGES = [
   ('de', _('German')),
   ('en', _('English')),
   ('fr', _('French')),
   ('es', _('Spanish')),
   ('pt', _('Portuguese'))
]

并在我的应用程序中创建了 locale 目录.

and created locale directory inside my app.

现在我在我的应用程序树中,并发出以下命令:

now I am inside my app tree and giving this command:

django-admin.py makemessages --all

这是吐出来​​的

#!C:\workspace\newsportal\venv_np\Scripts\python.exe
# EASY-INSTALL-SCRIPT: 'django==1.6','django-admin.py'
__requires__ = 'django==1.6'
import pkg_resources
pkg_resources.run_script('django==1.6', 'django-admin.py')

并且不在 locale 内部创建消息文件.

and NOT creating messagefiles inside locale.

我尝试过:

python manage.py makemessages --all

但是它找不到 manage.py ,因为我在我的应用程序中,而不在项目树中.正常情况如何?

but it cannot find manage.py because i am inside my app, not in project tree. how is it done normally?

推荐答案

您只需要将语言环境目录路径添加到 LOCALE_PATHS .例如:

You just need to add your locale directory paths to LOCALE_PATHS. For example:

LOCALE_PATHS = [
    os.path.join(BASE_DIR, "locale"),
    os.path.join(BASE_DIR, "yourapp/locale"), 
]

在项目中包含一些要翻译的文本后,只需对要翻译的每种语言执行此命令.就您而言:

Once you have included some text to be translated in your project, just execute this command for each language you want to translate. In your case:

django-admin.py makemessages -l de
django-admin.py makemessages -l en
django-admin.py makemessages -l fr
django-admin.py makemessages -l es
django-admin.py makemessages -l pt

然后翻译所有文本并进行编译.我建议为此目的使用 django-rosetta ,这是一个简化翻译的Django应用程序Django项目的过程.

Then translate all the texts and compile them. I recommend to use django-rosetta for this purpose, which is a Django application that eases the translation process of your Django projects.

django-admin.py makemessages --all

一切都应该正常工作

这篇关于如何使用django-admin.py makemessages --all的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆