Skip to main content

Wagtail Modeltranslation

This app is built using core features of django-modeltranslation: https://github.com/deschler/django-modeltranslation

It’s an alternative approach for i18n support on Wagtail CMS websites.

The wagtail-modeltranslation application is used to translate dynamic content of existing Wagtail models to an arbitrary number of languages, without having to change the original model classes. It uses a registration approach (comparable to Django’s admin app) to add translations to existing or new projects and is fully integrated into the Wagtail admin UI.

The advantage of a registration approach is the ability to add translations to models on a per-app basis. You can use the same app in different projects, whether or not they use translations, and without touching the original model class.

https://github.com/infoportugal/wagtail-modeltranslation/blob/master/screenshot.png?raw=true

Features

  • Add translations without changing existing models or views

  • Translation fields are stored in the same table (no expensive joins)

  • Supports inherited models (abstract and multi-table inheritance)

  • Handle more than just text fields

  • Wagtail admin integration

  • Flexible fallbacks, auto-population and more!

  • Default Page model fields has translatable fields by default

  • StreamFields are now supported!

Caveats

wagtail-modeltranslation patches Wagtail’s Page model with translation fields title_xx, slug_xx, seo_title_xx, search_description_xx and url_path_xx where “xx” represents the language code for each translated language. This is done without migrations through command sync_page_translation_fields. Since Page model belongs to Wagtail it’s within the realm of possibility that one day Wagtail may add a conflicting field to Page thus interfering with wagtail-modeltranslation.

Wagtail’s slugurl tag does not work across languages. wagtail-modeltranslation provides a drop-in replacement named slugurl_trans which by default takes the slug parameter in the default language.

Quick start

  1. Install wagtail-modeltranslation:

    pip install wagtail-modeltranslation
  2. Add ‘wagtail_modeltranslation’ to your INSTALLED_APPS setting like this (before all apps that you want to translate):

    INSTALLED_APPS = (
        ...
        'wagtail_modeltranslation',
        'wagtail_modeltranslation.makemigrations',
        'wagtail_modeltranslation.migrate',
    )
  3. Add ‘django.middleware.locale.LocaleMiddleware’ to MIDDLEWARE on your settings.py:

    MIDDLEWARE = (
        ...
        'django.middleware.locale.LocaleMiddleware',  # should be after SessionMiddleware and before CommonMiddleware
    )
  4. Enable i18n on settings.py:

    USE_I18N = True
  5. Define available languages on settings.py:

    from django.utils.translation import gettext_lazy as _
    
    LANGUAGES = (
        ('pt', _('Portuguese')),
        ('es', _('Spanish')),
        ('fr', _('French')),
    )
  6. Create translation.py inside the root folder of the app where the model you want to translate exists:

    from .models import Foo
    from modeltranslation.translator import TranslationOptions
    from modeltranslation.decorators import register
    
    @register(Foo)
    class FooTR(TranslationOptions):
        fields = (
            'body',
        )
  7. Run python manage.py makemigrations followed by python manage.py migrate (repeat every time you add a new language or register a new model)

  8. Run python manage.py sync_page_translation_fields (repeat every time you add a new language)

  9. If you’re adding wagtail-modeltranslation to an existing site run python manage.py update_translation_fields

Supported versions

Title

wagtail-modeltranslation release

Compatible Wagtail versions

Compatible Django versions

Compatible Python versions

0.10

>= 1.12, < 2.12

>= 1.11

2.7, 3.4, 3.5, 3.6

0.11

>= 2.13, < 3.0

>= 3.0

3.6, 3.7, 3.8, 3.9

0.12

>= 3.0, < 4.0

>= 3.2

3.7, 3.8, 3.9, 3.10

0.13

>= 4.0, < 5.0

>= 3.2

3.7, 3.8, 3.9, 3.10

0.14

>= 5.0, < 6.0

>= 3.2

3.8, 3.9, 3.10, 3.11

0.15

>= 5.2

>= 4.2

3.9, 3.10, 3.11, 3.12

0.16

>= 6.4

>= 4.2

3.9, 3.10, 3.11, 3.12, 3.13

Upgrade considerations (v0.10.8)

  • Template tag change_lang now needs a second parameter, page

Upgrade considerations (v0.8)

This version includes breaking changes as some key parts of the app have been re-written:

  • The most important change is that Page is now patched with translation fields.

  • WAGTAILMODELTRANSLATION_ORIGINAL_SLUG_LANGUAGE setting has been deprecated.

To upgrade to this version you need to:

  • Replace the WagtailTranslationOptions with TranslationOptions in all translation.py files

  • Run python manage.py sync_page_translation_fields at least once to create Page’s translation fields

  • Replace any usages of Wagtail’s {% slugurl ... %} for wagtail-modeltranslation’s own {% slugurl_trans ... %}

  • While optional it’s recommended to add 'wagtail_modeltranslation.makemigrations' to your INSTALLED_APPS. This will override Django’s makemigrations command to avoid creating spurious Page migrations.

Upgrade considerations (v0.6)

This version has some important changes as there was a refactoring to include django-modeltranslation as a dependency instead of duplicating their code in our version. This allow us to focus on Wagtail admin integration features as django-modeltranslation is very well mantained and is very quickly to fix problems with the latest Django versions. This way we also keep all the django-modeltranslation features (if you want you can also customize django-admin, for example). We also provide a new class to create the translation options classes: WagtailTranslationOptions Most of the changes are related to imports as they change from wagtail-modeltranslation to modeltranslation.

To upgrade to this version you need to:

  • Replace the TranslationOptions with WagtailTranslationOptions in all translation.py files

  • The import of the register decorator is now from modeltranslation.decorators import register

  • The import of translator is now from modeltranslation.translator import translator

Project Home

https://github.com/infoportugal/wagtail-modeltranslation

Documentation

http://wagtail-modeltranslation.readthedocs.io/

Download files

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

Source Distribution

wagtail_modeltranslation-0.16.0.tar.gz (49.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_modeltranslation-0.16.0-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_modeltranslation-0.16.0.tar.gz.

File metadata

File hashes

Hashes for wagtail_modeltranslation-0.16.0.tar.gz
Algorithm Hash digest
SHA256 2978cbfd7ec173f9767880fa7fcb4f4c915426e636faf82b052053873dfd94bb
MD5 438704d1f574e089ef2c33d664371484
BLAKE2b-256 159be27358462c54a8c6a76d50181150b1e5f1a8a84667ef0698b49f05c57d7e

See more details on using hashes here.

File details

Details for the file wagtail_modeltranslation-0.16.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_modeltranslation-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0e8bd0fe4ce8310f5acd67c1362428eeb0c653e0fac00ee0a44707c791bc5d5
MD5 248d9c94ab296d23bbeeb955297014bf
BLAKE2b-256 a35028a50cbe306b8546e28c5340c32f78144fca51b3391e2b9368d29a069942

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.16.0 This release

2 files

0.15.2

2 files

0.15.1

2 files

0.15.0

2 files

0.14.4

2 files

0.14.3

2 files

0.14.2

2 files

0.14.1

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.18

2 files

0.10.17

2 files

0.10.16

2 files

0.10.15

2 files

0.10.14

2 files

0.10.13

2 files

0.10.12

2 files

0.10.10

1 file

0.10.9

1 file

0.10.8

1 file

0.10.7

1 file

0.10.6

1 file

0.10.5

1 file

0.10.4

1 file

0.10.2

1 file

0.10.1

1 file

0.10

1 file

0.9.0

2 files

0.8.1

1 file

0.8

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4

1 file

0.3.6

1 file

0.3.5

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

0.2.0

1 file

0.1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page