I am attempting a navbar translation to simplified Chinese in Django, however, only the first word is being translated. To wit, I have created a navbar.html
with the following content:
{% load i18n %}
<li><a href="{% url 'homepage' %}">{% trans 'Home' %}</a></li>
<li><a href="{% url 'security' %}">{% trans 'Security' %}</a></li>
I then do a ./manage.py makemessages -l zh_CN
and constructed a file django.po
which contains
#: templates/navbar.html:20
msgid "Home"
msgstr "首页"
#: templates/navbar.html:25
msgid "Security"
msgstr "安全性"
I then did a ./manage.py compilemessages
to get the django.mo
, which appears to have all the translations I need.
As opposed to this question, my LOCALE_PATHS
is indeed a tuple:
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
and my LocaleMiddleware
is after SessionMiddleware
and before CommonMiddleware
, as the documentation specifies:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
Yet nonetheless, only Home
is translated; all other template variables are left untranslated.
To add a bit more mystery, I translated the navbar to Spanish and all variable were translated properly in the browser. This made me suspect my browser was not using the correct language code, so I ran ./manage.py makemessages -l zh-hans
and copied over the translation from the zh_CN
directory, but no dice.
Following this, I have removed all instances of #, fuzzy
, to no avail.
I am on Django 1.10.3 and Python 3.5.