无法在 django all-auth 中使用 i18n
Failing to use i18n in django all-auth
Django allauth 模块带有 i18n'd 模板和视图,我想用它们来让我的页面以法语显示。但是,只有使用 _() 呈现的文本才能正确翻译。
在模板中,{% trans %}
和 {% blocktrans %}
不输出翻译后的文本,但 {% get_current_language %}
returns 输出正确的标签。
设置示例:
USE_I18N = True
django.core.context_processors.i18n
TEMPLATES = [{
'BACKEND':'django.template.backends.django.DjangoTemplates',
'DIRS': ['mydir/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.contrib.messages.context_processors.messages',
],
},
},
},]
LOCALE_PATHS = ['/abs/path/to/locale',]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
LANGUAGE_CODE = 'fr'
LANGUAGES = ('fr',)
模板:
{% extends "account/base.html" %}
{% load i18n %}
...
{% trans "Signup" %}
...
abs/path/to/locale/fr/LC_MESSAGES/django.po,第 666-667 行:
msgid "Signup"
msgstr "Inscription"
我不知道去哪里看,我尝试重新启动服务器并清空缓存但没有成功。任何帮助将不胜感激。
编辑:运行 python manage.py compilemessages
解决了问题。自我注释:RTFM
仔细检查您编译的文件是否带有翻译。
Django allauth 模块带有 i18n'd 模板和视图,我想用它们来让我的页面以法语显示。但是,只有使用 _() 呈现的文本才能正确翻译。
在模板中,{% trans %}
和 {% blocktrans %}
不输出翻译后的文本,但 {% get_current_language %}
returns 输出正确的标签。
设置示例:
USE_I18N = True
django.core.context_processors.i18n
TEMPLATES = [{
'BACKEND':'django.template.backends.django.DjangoTemplates',
'DIRS': ['mydir/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.contrib.messages.context_processors.messages',
],
},
},
},]
LOCALE_PATHS = ['/abs/path/to/locale',]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
LANGUAGE_CODE = 'fr'
LANGUAGES = ('fr',)
模板:
{% extends "account/base.html" %}
{% load i18n %}
...
{% trans "Signup" %}
...
abs/path/to/locale/fr/LC_MESSAGES/django.po,第 666-667 行:
msgid "Signup"
msgstr "Inscription"
我不知道去哪里看,我尝试重新启动服务器并清空缓存但没有成功。任何帮助将不胜感激。
编辑:运行 python manage.py compilemessages
解决了问题。自我注释:RTFM
仔细检查您编译的文件是否带有翻译。