Django translations doesn't work !!!

500 views
Skip to first unread message

nameless

unread,
May 9, 2010, 4:35:35 AM5/9/10
to Django users


I have:

* created translation strings in the template and in the
application view.
* run this command: django-admin.py makemessages -l it and the
file it/LC_MESSAGES/django.po has been created
* translated strings in the django.po file.
* run this command: django-admin.py compilemessages and I receive:
processing file django.po in /home/jobber/Desktop/library/books/locale/
it/LC_MESSAGES
* set this in settings.py:

LANGUAGE_CODE = 'it'

TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.auth",

"django.core.context_processors.debug",

"django.core.context_processors.i18n",

"django.core.context_processors.media", )

USE_I18N = True

MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware',

'django.middleware.locale.LocaleMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

)

but.... translation doesn't work !! I always see english text. Why ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

leveille

unread,
May 9, 2010, 11:11:35 AM5/9/10
to Django users
Take a look at (http://docs.djangoproject.com/en/dev/topics/i18n/
deployment/#id1). Specifically, look at how LocaleMiddleware tries to
determine the the user's language preference.

(1) Session >> (2) Cookie >> (3) Accept-Language >> (4) LANGUAGE_CODE
setting

From the docs:

* If all you want to do is run Django with your native language, and a
language file is available for it, all you need to do is set
LANGUAGE_CODE.
* If you want to let each individual user specify which language he or
she prefers, use LocaleMiddleware. LocaleMiddleware enables language
selection based on data from the request. It customizes content for
each user.

So, if you don't want individual users to specify which language they
prefer (and you want LANGUAGE_CODE to drive your language display),
remove LocaleMiddleware.
Reply all
Reply to author
Forward
0 new messages