2

在我的 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 中有翻译

为什么 ?

这是中间件:

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',
)
4

2 回答 2

1
  1. 确保USE_I18N = True在设置
  2. 使用相同的代码, 'ru', forLANGUAGE_CODE和第一项的键LANGUAGES
  3. 确保Accept-Language您的请求标头'ru'中的优先级更高。
  4. As mega.venik's suggestion, ensure there is translation for the string in po and mo files in findable locale directory.
于 2012-04-18T16:44:56.333 回答
0

首先-您确定该LANGUAGE设置还涵盖错误消息吗?

第二——检查值的正确性LANGUAGE_CODE。根据文档,它应该是小写的

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

于 2012-04-18T16:18:36.257 回答