Valorad
Valorad

Reputation: 736

django 1.10 translation, though language switched, no translation appeared

I'm using Django 1.10. What I want is, to add Chinese translation to my page.

Although the language is switched to zh-hans, the translation does not successfully appear.

I was referring to the official guide https://docs.djangoproject.com/en/1.10/topics/i18n/translation/ Here's what I have in my code. (I'm using local)

settings.py

...
MIDDLEWARE = [
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
]
TEMPLATES = [
    { ...
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.i18n',
                ...
            ],},},]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'))
...

index.html, which is in the "home" app:

...
<!-- Current language: {{ LANGUAGE_CODE }} -->
<p>{% blocktrans %}Harbor. Shelter. WC. SDK.{% endblocktrans %}</p>
...

django.po, located in (root)/locale/zh_hans/LC_MESSAGES

#: home/templates/home/index.html:23 msgid "Harbor. Shelter. WC. SDK." msgstr "高端黑"

Then I re-compiled the message, restarted the server, and then reloaded the page. (I was using go-incognito, which means no cache existed.)

From {{ LANGUAGE_CODE }} in the comment section, I could see the language was switched pretty fine, already being "zh-hans".

However, the translation did not show up, the string was still "Harbor. Shelter. WC. SDK.", remaining untranslated.

What was wrong? What did I miss?

Upvotes: 0

Views: 310

Answers (1)

ALUW
ALUW

Reputation: 397

You've probably already solved this issue given that you posted this so long ago but this is what I found works. Thought I'd let you know just in case.

The solution I found (I don't know why it works... must be a bug) is to create the locale folder with an underscore and a capital H.

So it would look like:

django-admin makemessages -l zh_Hans

Upvotes: 1

Related Questions