Making the page language selectable¶
Pages may come in varying languages.
LanguageMixin helps with that.
It adds a
language_code field to the model which allows selecting
the language based on
settings.LANGUAGES. The first language is set
from django.utils.translation import gettext_lazy as _ from feincms3.mixins import LanguageMixin from feincms3.pages import AbstractPage class Page(LanguageMixin, AbstractPage): pass
Activating the language¶
activate_language method is the preferred way to activate the
page’s language for the current request. It runs
django.utils.translation.activate and sets
to the value of
django.utils.translation.get_language, the same
activate may fail and
get_language might return a
different language, however that’s not specific to feincms3.
def page_detail(request, path): page = ... # MAGIC! (or maybe get_object_or_404...) page.activate_language(request) ...
page.activate_language does not persist the language across
requests as Django’s
set_language modifies the session and sets cookies.) That is
mostly what you want though since the page’s language is tied to its
Page tree tips¶
I most often add a root page per language, which means that the main
tree_depth would be
0. The menu template
tags described in Navigation generation recipes would also require an additional
statement to only return pages in the current language.
A page tree might look as follows then:
Home (EN) - About us - News Startseite (DE) - Über uns - Neuigkeiten Page d'acceuil (FR) - A propos de nous - Actualité