Search code examples
djangodjango-i18n

Chinese django translations not working


My settings.py looks like this:

LANGUAGES = (
    ('en', _('English')),
    ('fr', _('French')),
    #Simplified Chinese
    ('zh-hans', _('Simplified Chinese')),
)

In my template I have:

<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>

and

<button type="submit" value="zh-hans" name='language'>{% trans 'Simplified Chinese' %}</button>

And in my urls.py I have:

url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),

In my po file I have:

msgid "Menu"
msgstr "菜单"

I compiled the messages but it doesn't work. I have working translations for french so I don't understand what is going on with the Chinese translations.

EDIT: So I tried to put the Chinese translation for "Menu" into my french po file because I thought it might be the characters themselves but it worked. Then When I put it back into the Chinese po file, "Menu" didn't get translated.


Solution

  • For those of you having the same issue, the solution I found is to create the locale folder with an underscore and a capital H.

    So it would look like:

    django-admin makemessages -l zh_Hans
    

    The reason is that the Django documentation states:

    In all cases the name of the directory containing the translation is expected to be named using locale name notation. E.g. de, pt_BR, es_AR, etc.

    and in another part of the documentation says:

    A locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC. Examples: it, de_AT, es, pt_BR. The language part is always in lower case and the country part in upper case. The separator is an underscore.