1. Internationalization

1.1. Multilingual URLs

If you use more than one language, django CMS urls need to be referenced via i18n_patterns(). For more information about this see the official django documentation.

Main urls.py example:

  1. from django.conf import settings
  2. from django.conf.urls.defaults import patterns, include, url
  3. from django.contrib import admin
  4. from django.conf.urls.i18n import i18n_patterns
  5. from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  6. admin.autodiscover()
  7. urlpatterns = patterns('',
  8. url(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
  9. )
  10. urlpatterns += staticfiles_urlpatterns()
  11. urlpatterns += i18n_patterns('',
  12. url(r'^admin/', include(admin.site.urls)),
  13. url(r'^', include('cms.urls')), # <--------- include the django cms urls via i18n_patterns
  14. )

By default if someone visits a page at http://www.mysite.fr/ django determines the language as follow:

  • language in url
  • language in session
  • language in cookie
  • language in from browser
  • LANGUAGE_CODE from settings

No if i have a German browser and visit a page that is only English and French, it will choose the language that is in LANGUAGE_CODE. If this is English but i only speak French i have to switch the language. No if after sometime i visit the page again. The page will display in English again and I have to switch again. The same is for every link that points to / will switch to English again. To fix this behavior the cms ships with a middleware:

cms.middleware.language.LanguageCookieMiddleware

add this to you middleware settings fix this.

1.3. Language Chooser

The language_chooser template tag will display a language chooser for the current page. You can modify the template in menu/language_chooser.html or provide your own template if necessary.

Example:

  1. {% load menu_tags %}
  2. {% language_chooser "myapp/language_chooser.html" %}

1.4. page_language_url

This template tag returns the URL of the current page in another language.

Example:

  1. {% page_language_url "de" %}

1.5. hide_unstranslated

If you add a default directive to your CMS_LANGUAGES with a hide_unstranslated to False all pages will be displayed in all languages even if they are not translated yet.

If hide_untranslated is True in your CMS_LANGUAGES and you are on a page that doesn’t yet have an English translation and you view the German version then the language chooser will redirect to /. The same goes for urls that are not handled by the cms and display a language chooser.

1.6. Automated slug generation unicode characters

If your site has languages which use non-ASCII character sets, you might want to enable CMS_UNIHANDECODE_HOST and CMS_UNIHANDECODE_VERSION to get automated slugs for those languages too.