Skip to main content

Translatable flatpages

Project description

django-flatpages-i18n
=====================

Translatable version of django.contrib.flatpages

Installation
-------------

```
$ pip install django-flatpages-i18n
```

Add new applications at the end of INSTALLED_APPS in your settings.py.

```python
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',

'south',
'modeltranslation',
'flatpages_i18n',
)
```

Before the migration we need create the list of all available languages in settings.py.

```python
LANGUAGE_CODE = 'en'

from django.utils.translation import gettext

LANGUAGES = (
('de', gettext('German')),
('en', gettext('English')),
)
```
Don't forget to add an FlatpageFallbackMiddleware into MIDDLEWARE_CLASSES.

```python
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.middleware.locale.LocaleMiddleware', # Don't forget
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'flatpages_i18n.middleware.FlatpageFallbackMiddleware'
)
```

Run the migrations.

```
$ python manage.py schemamigration flatpages_i18n --init
$ python manage.py migrate flatpages_i18n
```

{% load i18n flatpages %}

{% get_available_languages as LANGUAGES %}
{% get_flatpages_i18n as flatpages_i18n %}

Usage
------

templates/home.html

```
{% load i18n flatpages %}

{% 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>
```

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.1.1.tar.gz (6.1 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-flatpages-i18n-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e58cea74d6d0e69fce05c671c9fda83068f64ac791430515aaa6622e26175c72
MD5 8e498093473af8a2a3f64678ba0fde37
BLAKE2b-256 0e5cfea90147d68a46a68e6413b53e79c16b301c0c7dd86881001e361ba625fa

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