0

我有一个多语言网站(it、en、ru),它使用 django-cms 和一些挂在各个页面上的应用程序。我的问题是内容始终以意大利语提供,即使我访问以“/en/”或“/ru/”为前缀的页面。在我的基本模板 (base.html) 上,我有一个 {{ lang }} 模板变量,它允许我检索当前页面语言,它工作得很好......直到今天。现在,如果我访问wwww.myhomepage/en(或/ru),“lang”的值始终是“it”。

这些是我的语言设置(cms 而不是 cms)以及与语言相关的其他设置:

LANGUAGE_CODE = 'it' 

DEFAULT_LANGUAGE = 0

LANGUAGES = (
    ('it', gettext(u'Italiano')),
    ('en', gettext(u'English')),
    ('ru', gettext(u'Russian')),     )                                                                                                                                                                  

CMS_LANGUAGES = (
    ('it', ugettext('Italian')),
    ('en', ugettext('English')),
    ('ru', ugettext('Russian')),
)

LOCALE_PATHS = (os.path.join(PROJECT_PATH, 'locale'))

CMS_LANGUAGE_CONF = {
    'it': ['en'],
    'ru': ['en'],
    }  

CMS_HIDE_UNTRANSLATED = False

    MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'cms.middleware.multilingual.MultilingualURLMiddleware',
     'cms.middleware.page.CurrentPageMiddleware',
     'cms.middleware.user.CurrentUserMiddleware',
     'cms.middleware.toolbar.ToolbarMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'cms.middleware.multilingual.MultilingualURLMiddleware',
     'cms.middleware.page.CurrentPageMiddleware',
     'cms.middleware.user.CurrentUserMiddleware',
     'debug_toolbar.middleware.DebugToolbarMiddleware',
     'cms.middleware.multilingual.MultilingualURLMiddleware',
     'cms.middleware.page.CurrentPageMiddleware',
     'cms.middleware.user.CurrentUserMiddleware',
     'cms.middleware.toolbar.ToolbarMiddleware'
)

有什么帮助吗?谢谢

4

1 回答 1

0

您有几个在您的设置中重复的中间件。它们应该看起来像这样:

MIDDLEWARE_CLASSES = (
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',

 'cms.middleware.multilingual.MultilingualURLMiddleware',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware',
)

另外,您也可以提供您的CONTEXT_PROCESSOR设置吗?

然后,我假设您使用的是 Django-cms <= 2.3.5。这是正确的吗?有一个 2.4 测试版正在摆脱 MultilingualMiddleware,如果您可以尝试它是否适合您(即使它仍然是测试版)。

于 2013-01-30T09:22:18.990 回答