Reputation: 397
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.
Upvotes: 3
Views: 2202
Reputation: 131
This issue indeed confused me a lot! Here's a short summary base on ALUW's answer:
# in settings.py, use lower-case language code, The separator is a dash.
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'), )
LANGUAGES = (
('en', _('English')),
#Simplified Chinese
('zh-hans', _('Simplified Chinese')),
)
# while when making and compiling message file, use local name.
# The language part is always in lower case and the country part in upper case.
# The separator is an underscore.
./manage.py makemessages -l zh_Hans
Upvotes: 0
Reputation: 397
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.
Upvotes: 10
Reputation: 1
Is your chinesse locale directory named 'zh_hans' instead of 'zh-hans'? I believe the directory must have underscore instead of dash.
Upvotes: 0