我在我的项目中使用多个翻译
为此,我已将我的设置文件更新为
LANGUAGE_CODE = 'en-us'
gettext = lambda s: s
LANGUAGES = (
('es', gettext('Spanish')),
('en', gettext('English')),
)
LOCALE_PATHS = (
'/mnt/aviesta/pythondev/django/locale',
)
USE_I18N = True
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.request",
)
我的模板文件为:
{% load i18n %}
{% trans "Hello" %}
<p>Already a user <a href="/login/"><b>{% trans "login here" %}</b></a></p>
之后,我创建了一个与我的应用程序平行的语言环境文件夹,而不是在其中创建特定语言文件夹:django-admin.py makemessages -l es创建 .po 文件,然后将此 .po 文件更新为:
#: customer_reg/customer_register.html:14
msgid "Hello"
msgstr "¡Hola"
#: customer_reg/customer_register.html:17
msgid "login here"
msgstr "ingresa aquí"
最后我编译了我的 msg django-admin.py compilemessages
但是我的字符串“hello”和“login here”仍然是英文,它们没有翻译。我不知道为什么会这样??