Translatable version of django.contrib.flatpages with basic menu support.
- Django
- South
- django_modeltranslation
- django_mptt
Tested on Django 1.4.5.
Install python library using pip:
pip install django-flatpages-i18n
Add
south
,mptt
,modeltranslation
andflatpages_i18n
toINSTALLED_APPS
in your Django settings fileAdd
flatpages_i18n.middleware.FlatpageFallbackMiddleware
toMIDDLEWARE_CLASSES
in your Django settings fileSpecify desired languages in your Django settings file:
from django.utils.translation import gettext LANGUAGE_CODE = 'en' LANGUAGES = ( ('en', gettext('English')), ('de', gettext('German')), )
Sync and migrate your database
Run
sync_translation_fields
andupdate_translation_fields
commands (frommodeltranslation
app)If you want to use Redactor WYSIWYG editor (see settings below), you need to add
'flatpages_i18n.urls'
to your urls.py:if 'flatpages_i18n' in settings.INSTALLED_APPS: urlpatterns += i18n_patterns('', url(r'^', include('flatpages_i18n.urls')), )
In your HTML template:
{% load i18n flatpages_i18n %} {% get_available_languages as LANGUAGES %} {% get_flatpages_i18n as flatpages_i18n %} <ul> {% for flatpage in flatpages_i18n %} <li><a href="/{{ LANGUAGE_CODE }}{{ flatpage.url }}">{{ flatpage.title }}</a></li> {% endfor %} </ul>
To get flatpage by its PK:
{% get_flatpage_i18n 123 as my_flatpage %} {{ my_flatpage.content }}
or by its machine_name:
{% get_flatpage_i18n 'my-flatpage' as my_flatpage %}
To print all menu items:
<div id="navigation"> {% get_menu %} </div>
to get only children of menu item identified by its PK:
<div id="navigation"> {% get_menu 2 %} </div>
or by its machine_name:
<div id="navigation"> {% get_menu 'footer-menu' %} </div>
- FLATPAGES_EDITOR
- If you wish to use Redactor as WYSIWYG editor, set it to
'REDACTOR'
. Default:None
. - FLATPAGES_REDACTOR_JS
- Path to Redactor .js file. Default:
'js/redactor/redactor.js'
. - FLATPAGES_REDACTOR_CSS
- Path to Redactor .css file. Default:
'css/redactor/redactor.css'
.
Library is by Lukas Vinclav and Erik Telepovsky from Pragmatic Mates. See our other libraries.