Vlad
Vlad

Reputation: 977

django did not use his localization file

Have this code in my settings.py file:

LANGUAGES = (
  ('ru', 'Russian'),
)
DEFAULT_LANGUAGE = 0
LANGUAGE_CODE = 'ru-RU'

but error:

raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive.")) 

return message in english language, although that django has translation in django /usr/local/lib/python-2.7/dist-packages/django/contrib/locale/ru/LC_MESSAGES/django.po

Why ?

Here is MIDDLWARE:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
    # 'cms.middleware.multilingual.MultilingualURLMiddleware',
    # 'django.middleware.transaction.TransactionMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'pagination.middleware.PaginationMiddleware',
    'banner_middleware.Banner',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth',
    'django.core.context_processors.i18n',
    "django.core.context_processors.debug",
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'cms.context_processors.media',
    'sekizai.context_processors.sekizai',
)

Upvotes: 2

Views: 616

Answers (2)

mega.venik
mega.venik

Reputation: 658

First of all - are you sure, that LANGUAGE setting also covers error messages?

Sencond - check the correctness of the LANGUAGE_CODE value. According to the documentation, it should be in lower case

By the way, try to add 'django.middleware.locale.LocaleMiddleware'to the settings.MIDDLEWARE_CLASSES.

Upvotes: 0

okm
okm

Reputation: 23871

  1. ensure USE_I18N = True in settings
  2. use same code, 'ru', for LANGUAGE_CODE and the key of the first item in LANGUAGES
  3. ensure the Accept-Language in your request header take 'ru' with higher priority.
  4. As mega.venik's suggestion, ensure there is translation for the string in po and mo files in findable locale directory.

Upvotes: 1

Related Questions