我试图将翻译添加到我的项目中。由于我不是专家,我想先测试一个非常简单的例子。
我遵循了多个教程,包括官方文档,但我可能遗漏了一些东西。
到目前为止我做了什么:
SETTINGS.PY:
MIDDLEWARE_CLASSES = (
...
'django.middleware.locale.LocaleMiddleware',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
...
'django.core.context_processors.i18n',
],
},
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# list of languages used
LANGUAGES = [
( 'en', _('English') ),
( 'fr', _('French') ),
]
# directory that will host po and mo files
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
models.py (只更改了一个属性以查看管理中的效果)
class Level(models.Model):
LEVEL_CHOICES = (
('unknown', ugettext_lazy('Unknown')),
('standard', ugettext_lazy('Standard level')),
('professional', ugettext_lazy('Professional level')),
('native', ugettext_lazy('Native speaker level')),
)
name = models.CharField(max_length=40, choices=LEVEL_CHOICES, blank=False, null=False)
我已经安装了GETTEXT
操作系统:Windows 8.1 64位
现在我期望在.po
目录中找到locale
个文件。
所以我跑了:
django-admin makemessages
返回错误:
CommandError: Can't find xgettext. Make sure you have GNU gettext tools 0.15 or
newer installed.
所以我试过了:
python manage.py makemessages --locale=fr_FR --locale=en_US
返回:
CommandError: Can't find msguniq. Make sure you have GNU gettext tools 0.15 or n
ewer installed.
你们知道我做错了什么吗?我已经阅读了文档,也许我错过了一些东西。