Ich arbeite in einer Django 1.9/python 3.5-Anwendung und versuche, Djangos Übersetzungsprogramm zu verwenden. Ich habe ein Locale-Verzeichnis, das ein 'es' -Verzeichnis für spanische Übersetzungen hat, in denen ich eine .po-Datei erstellt habe. Ich habe es eingerichtet, um ein paar Übersetzungen zu haben, nur um es zu testen.Django Translations funktioniert nicht
msgid "Sign In"
msgstr "Registrarse"
msgid "Create an Account"
msgstr "Crea una cuenta"
Ich habe meine Einstellung Datei korrekt als auch konfiguriert
MIDDLEWARE_CLASSES = (
'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',
'webapp.middleware.LanguageSwitchMiddleware',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'webapp.context_processors.detail_context',
'django.template.context_processors.i18n'
],
},
},
]
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LOCALE_PATHS = (
os.path.join(PROJECT_ROOT, 'locale/'),
)
from django.utils.translation import ugettext_lazy as _
LANGUAGES = (
('en', _('English')), # first language is the default used by modeltranslations
('es', _('Spanish')),
)
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Chicago'
USE_I18N = True
In meiner Vorlage verwende ich die Django ‚trans‘ Template-Tag für die Worte anmelden und ein Konto erstellen. Ein Auswahlfeld bearbeitet den Content-Language-HTTP-Antwortheader von der Anwendung, die ich getestet habe, und es wird erfolgreich ausgeführt. Die Header signieren, und create und account, übersetzen nicht ins Spanische. Gibt es einen Schritt, den ich vermisse?
HTML
{% load i18n %}
<ul class="list-inline-xxs">
{% if customer %}
<li>
Welcome,
<a href='{% url "customer:dashboard" %}'>
{{ customer.first_name }}
</a>
</li>
<li>
<a href='{% url "customer:logout" %}'>
{% trans 'Logout' %}
</a>
</li>
{% else %}
<li>
<a href='{% url "customer:login" %}'>
{% trans 'Sign In' %}
</a>
</li>
<li>
<a href='{% url "subscription:customer-subscribe" %}'>
{% trans 'Create an Account' %}
</a>
</li>
{% endif %}
</ul>
Alles sieht gut aus. Was hast du in webapp.middleware.LanguageSwitchMiddleware? –