简体   繁体   中英

Failing to use i18n in django all-auth

Django allauth module comes with i18n'd templates and views that I would like to use to get my page displayed in French. However, only the text rendered with _() is correctly translated.

Inside the templates, the {% trans %} and {% blocktrans %} doesn't output translated text but {% get_current_language %} returns the correct tag.

Settings sample :

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',)

The template:

{% extends "account/base.html" %}
{% load i18n %}
...
{% trans "Signup" %}
...

abs/path/to/locale/fr/LC_MESSAGES/django.po, line 666-667 :

msgid "Signup"
msgstr "Inscription"

I'm out of ideas of where to look at, I tried restarting server and empty cache without success. Any help would be greatly appreciated.

EDIT: Problem solved by running python manage.py compilemessages . Note to self : RTFM

仔细检查您是否编译了带有翻译的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM