django没有使用他的本地化文件

时间:2012-04-18 14:26:22

标签: django localization internationalization

在我的settings.py文件中包含此代码:

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

但错误:

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

用英语返回留言,虽然django在django中有翻译/usr/local/lib/python-2.7/dist-packages/django/contrib/locale/ru/LC_MESSAGES/django.po

为什么?

这是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',
)

2 个答案:

答案 0 :(得分:0)

首先 - 您确定LANGUAGE设置还包含错误消息吗?

Sencond - 检查LANGUAGE_CODE值的正确性。根据{{​​3}},它应该是小写的

顺便说一下,尝试将'django.middleware.locale.LocaleMiddleware'添加到settings.MIDDLEWARE_CLASSES

答案 1 :(得分:0)

  1. 确保设置中的USE_I18N = True
  2. 'ru'使用相同的代码LANGUAGE_CODELANGUAGES
  3. 中第一项的键
  4. 确保请求标头中的Accept-Language'ru'获得更高优先级。
  5. 作为mega.venik的建议,请确保在可查找的语言环境目录中的po和mo文件中有字符串的翻译。