django-cms 的核心翻译不使用用户的语言

django-cms not using user's language for its core translations

编辑:发现这发生在 djangocms-installer 生成的一个非常基本的项目上,我已经报告 an issue about this

我已经使用 django-cms and my client's native language is french. Thanks to Transifex 设置了一个简单的项目,法语翻译始终是最新的。不太清楚为什么,与 django-cms 应用程序相关的所有内容都没有被翻译(管理中的字符串、管理工具栏等)。

"Double click to edit"、"Create Page" 等字符串仍然是英文,即使当前登录的用户将其设置设置为法语 (Accueil › Cms › User settings › gableroux)

请注意,管理中的所有其他字符串都已翻译成法语

Administration de Django
Bienvenue, gableroux. Modifier le mot de passe / Déconnexion
Administration du site

等等

生成的设置

*请注意,我没有在生产环境中使用这些设置,这是我针对这个特定问题生成的示例项目,SECRET_KEY 未在任何地方使用 ;)

import os
gettext = lambda s: s
DATA_DIR = os.path.dirname(os.path.dirname(__file__))
"""
Django settings for omg project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@j#r%*#u&2v!yxih1n11e)4gg%k+)1bm&=mdhdcpzn9#ptn597'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition





ROOT_URLCONF = 'omg.urls'

WSGI_APPLICATION = 'omg.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases



# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'fr'

TIME_ZONE = 'America/Chicago'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
STATIC_ROOT = os.path.join(DATA_DIR, 'static')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'omg', 'static'),
)
SITE_ID = 1

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader'
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware'
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
    'django.core.context_processors.i18n',
    'django.core.context_processors.debug',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.csrf',
    'django.core.context_processors.tz',
    'sekizai.context_processors.sekizai',
    'django.core.context_processors.static',
    'cms.context_processors.cms_settings'
)

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'omg', 'templates'),
)

INSTALLED_APPS = (
    'djangocms_admin_style',
    'djangocms_text_ckeditor',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.staticfiles',
    'django.contrib.messages',
    'cms',
    'menus',
    'sekizai',
    'mptt',
    'djangocms_style',
    'djangocms_column',
    'djangocms_file',
    'djangocms_flash',
    'djangocms_googlemap',
    'djangocms_inherit',
    'djangocms_link',
    'djangocms_picture',
    'djangocms_teaser',
    'djangocms_video',
    'south',
    'reversion',
    'omg'
)

LANGUAGES = (
    ## Customize this
    ('fr', gettext('fr')),
    ('en', gettext('en')),
)

CMS_LANGUAGES = {
    ## Customize this
    'default': {
        'public': True,
        'hide_untranslated': False,
        'redirect_on_fallback': True,
    },
    1: [
        {
            'public': True,
            'code': 'fr',
            'hide_untranslated': False,
            'name': gettext('fr'),
            'redirect_on_fallback': True,
        },
        {
            'public': True,
            'code': 'en',
            'hide_untranslated': False,
            'name': gettext('en'),
            'redirect_on_fallback': True,
        },
    ],
}

CMS_TEMPLATES = (
    ## Customize this
    ('fullwidth.html', 'Fullwidth'),
    ('sidebar_left.html', 'Sidebar Left'),
    ('sidebar_right.html', 'Sidebar Right')
)

CMS_PERMISSION = True

CMS_PLACEHOLDER_CONF = {}

DATABASES = {
    'default':
        {'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'project.db', 'HOST': 'localhost', 'USER': '', 'PASSWORD': '', 'PORT': ''}
}

如果您有任何想法或者您觉得我可以提供更多信息,请告诉我。

点冻结

Django==1.6.10
Pillow==2.7.0
South==1.0.2
argparse==1.3.0
dj-database-url==0.3.0
django-classy-tags==0.5.2
django-cms==3.0.9
django-mptt==0.6.1
django-reversion==1.8.5
django-sekizai==0.8.1
djangocms-admin-style==0.2.5
djangocms-column==1.5
djangocms-file==0.1
djangocms-flash==0.1
djangocms-googlemap==0.2
djangocms-inherit==0.1
djangocms-installer==0.7.1
djangocms-link==1.5
djangocms-picture==0.1
djangocms-style==1.5
djangocms-teaser==0.1
djangocms-text-ckeditor==2.4.3
djangocms-video==0.1
html5lib==0.999
pytz==2014.10
requests==2.5.1
six==1.9.0
wsgiref==0.1.2

郑重声明,此问题已在 django-cms 项目 Github 中得到解决:https://github.com/divio/django-cms/issues/3798

最终答案(一旦应用了删除语言环境的补丁 fr_FR)是重新启动服务器——只有在重新启动服务器时才会考虑语言环境。