I've been trying to get translations working on my Django installation, but have failed so far.
I've created a basic test setup to find my error, but no luck so far.
One of my views simply prints a translated text (or it should, but it always shows the non-translated text):
text = _('blah') return HttpResponse(text)
I generated a Dutch language file using python manage.py makemessages -l nl_BE
. The django.po is in locale/nl_BE/LC_MESSAGES.
I modified that application to translate "blah" in English to "blih" in Dutch:
#: foo/views.py:9` msgid "blah" msgstr "blih"
I've generated a django.mo file using python manage.py compilemessages
. The django.mo file is also in locale/nl_BE/LC_MESSAGES.
I've tried to change the default language in settings.py (LANGUAGE_CODE) to 'nl-be', but that didn't make a difference (so it's now on 'en-us'). USE_I18N is set to True.
I have a view that sets the language (using the /i18n/setlang/ url).
In this view, I also print:
{% get_current_language as LANGUAGE_CODE %} {% get_available_languages as LANGUAGES %} {% get_current_language_bidi as LANGUAGE_BIDI %}
This shows:
LANGUAGE_CODE: nl LA开发者_如何学CNGUAGES: [('ar', u'Arabisch'), ('bg', u'Bulgaars'), ('bn', u'Bengaals'), ('bs', u'Bosnian'), ('ca', u'Catalaans'), ('cs', u'Tjechisch'), ('cy', u'Welsh'), ('da', u'Deens'), ('de', u'Duits'), ('el', u'Grieks'), ('en', u'Engels'), ('en-gb', u'British English'), ('es', u'Spaans'), ('es-ar', u'Argentinian Spanish'), ('et', u'Ests'), ('eu', u'Baskisch'), ('fa', u'Perzisch'), ('fi', u'Fins'), ('fr', u'Frans'), ('fy-nl', u'Frisian'), ('ga', u'Iers'), ('gl', u'Galicisch'), ('he', u'Hebreews'), ('hi', u'Hindi'), ('hr', u'Kroatisch'), ('hu', u'Hongaars'), ('id', u'Indonesian'), ('is', u'IJslands'), ('it', u'Italiaans'), ('ja', u'Japans'), ('ka', u'Georgisch'), ('km', u'Khmer'), ('kn', u'Kannada'), ('ko', u'Koreaans'), ('lt', u'Litouws'), ('lv', u'Lets'), ('mk', u'Macedonisch'), ('ml', u'Malayalam'), ('mn', u'Mongolian'), ('nl', u'Nederlands'), ('no', u'Noors'), ('nb', u'Norwegian Bokmal'), ('nn', u'Norwegian Nynorsk'), ('pl', u'Pools'), ('pt', u'Portugees'), ('pt-br', u'Braziliaans Portugees'), ('ro', u'Roemeens'), ('ru', u'Russisch'), ('sk', u'Slovaaks'), ('sl', u'Sloveens'), ('sq', u'Albanian'), ('sr', u'Servisch'), ('sr-latn', u'Serbian Latin'), ('sv', u'Zweeds'), ('ta', u'Tamil'), ('te', u'Telegu'), ('th', u'Thais'), ('tr', u'Turks'), ('uk', u'Oekra\xefens'), ('vi', u'Vietnamese'), ('zh-cn', u'Vereenvoudigd Chinees'), ('zh-tw', u'Traditioneel Chinees')] LANGUAGE_BIDI: False
So nl should work. And in fact, it does. The LANGUAGES variable shows a list of languages displayed in Dutch. However, it doesn't display the Dutch translation for my application.
Is Django somehow not noticing my django.mo file? Am I forgetting something crucial?
精彩评论