I tried Django 1.7.
I tried the same method, but did not work the first time, after some debugging in Django, I found some hints and found a solution, there should be some kind of document in Django for locale names, in fact there are some rules not documented.
And in my test, only messages in the project can be downloaded, all messages in the application can not be translated.
I tried print _ (") in the same index () method in my application view. Msgstr" The file in settings.py can be translated.
The code is as follows:
def index (request):
print request.LANGUAGE_CODE str_msg = _("Welcome to poll list!")
After checking some Django code, I found that it is only allowed for locale names listed on the page
https://github.com/django/django/tree/master/django/conf/locale
Pay attention to the directory names, no 'ru-RU', no 'zh-cn'.
code in gettext.py:
def translation(domain, localedir=None, languages=None, class_=None, fallback=False, codeset=None): if class_ is None: class_ = GNUTranslations mofiles = find(domain, localedir, languages, all=1) if not mofiles: if fallback: return NullTranslations() raise IOError(ENOENT, 'No translation file found for domain', domain)
I fixed my own problem by changing "zh-cn" to "zh_CN", then executed the following commands:
python manage.py makemessages -l zh_CN
copied the django.po file from the folder '/ zh-cn / LC_MESSAGES /' to the folder '/ zh_CN / LC_MESSAGES' to save my translations.
python manage.py compilemessages
then
python manage.py runserver
Now everything is all right!
So, I think moving from ru-ru to ru might solve your problem.