0

It seems I don't understand how to set the default language for Django CMS. I want the default language to be set to Dutch. However, for an unknown reason, it always defaults to English when creating or after modifying/editing a Page.

Take the following scenario. I open the Page tree. English is selected by default. I select Dutch. I edit this page. I publish it. I click on edit, it opens the English page which is empty.

Take another scenario. I open the Page tree. I create a new page. By default it opens for the English variant.

Note: All cookies were removed as suggested in the documentation.

Please advise how I can set the default language to Dutch?

The settings:


from django.utils.translation import gettext_lazy as _

LANGUAGE_CODE = "nl"
SITE_ID = 1
USE_I18N = True

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "corsheaders.middleware.CorsMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.locale.LocaleMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.common.BrokenLinkEmailsMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
]

LANGUAGES = [
    ('nl', 'Dutch'),
    ('en', 'English'),
]

CMS_LANGUAGES = {
    1: [
        {
            'code': 'nl',
            'name': _('Dutch'),
            'fallbacks': ['en', ],
            'public': True,
            'hide_untranslated': True,
            'redirect_on_fallback': False,
        },
        {
            'code': 'en',
            'name': _('English'),
            'public': True,
        },
    ],
    'default': {
        'fallbacks': ['nl', 'en'],
        'redirect_on_fallback': False,
        'public': True,
        'hide_untranslated': True,
    }
}

sitWolf
  • 930
  • 10
  • 16

1 Answers1

0

I fixed the problem as follows per the documentation:

# urls.py

from django.conf.urls.i18n import i18n_patterns
from django.views.i18n import JavaScriptCatalog

# ...

admin.autodiscover()

urlpatterns = i18n_patterns(
    re_path(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
)

# Note the django CMS URLs included via i18n_patterns
urlpatterns += i18n_patterns(
    path(settings.ADMIN_URL, admin.site.urls),
    re_path(r'^', include('cms.urls')),
)
urlpatterns += [
    ...
]

This setup introduces other minor issues that need to be fixed. But in general, this is the solution.

On another note, not sure though as to why this part is needed:

re_path(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog')
sitWolf
  • 930
  • 10
  • 16