Skip to main content

Translatable flatpages

Project description

Translatable version of django.contrib.flatpages with basic menu support.

Requirements

  • Django

  • django_modeltranslation

  • django_mptt

Tested with Django 1.8.

Installation

  1. Install python library using pip: pip install django-flatpages-i18n

  2. Add mptt, modeltranslation and flatpages_i18n to INSTALLED_APPS in your Django settings file

  3. Add flatpages_i18n.middleware.FlatpageFallbackMiddleware to MIDDLEWARE_CLASSES in your Django settings file

  4. Specify desired languages in your Django settings file:

    from django.utils.translation import gettext
    
    LANGUAGE_CODE = 'en'
    LANGUAGES = (
        ('en', gettext('English')),
        ('de', gettext('German')),
    )
  5. Migrate your database

  6. Run sync_translation_fields and update_translation_fields commands (from modeltranslation app)

  7. 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')),
        )

Usage

To get all flatpages:

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 %}

Settings

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'.

Authors

Library is by Erik Telepovsky from Pragmatic Mates. See our other libraries.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-flatpages-i18n-0.7.1.tar.gz (102.8 kB view details)

Uploaded Source

File details

Details for the file django-flatpages-i18n-0.7.1.tar.gz.

File metadata

File hashes

Hashes for django-flatpages-i18n-0.7.1.tar.gz
Algorithm Hash digest
SHA256 9d71bcd9ed6b159c56089220ea510dd62ffe3bca406e2794fdb908bdae047f29
MD5 207a8d9b5fcea69675c5a34a2bfec2e1
BLAKE2b-256 2890c761a936339a7230c30f42b691e3c89d9281359111e3c140a49238d75df2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page