Package: wagtail-modeltranslation
Wagtail ModeltranslationThis app is built using core features of django-modeltranslation:https://github.com/deschler/django-modeltranslationIt’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.FeaturesAdd translations without changing existing models or viewsTranslation fields are stored in the same table (no expensive joins)Supports inherited models (abstract and multi-table inheritance)Handle more than just text fieldsWagtail admin integrationFlexible fallbacks, auto-population and more!Default Page model fields has translatable fields by defaultStreamFields are now supported!Caveatswagtail-modeltranslationpatches Wagtail’sPagemodel with translation fieldstitle_xx,slug_xx,seo_title_xx,search_description_xxandurl_path_xxwhere “xx” represents the language code for each translated language. This
is done without migrations through commandsync_page_translation_fields. SincePagemodel belongs to
Wagtail it’s within the realm of possibility that one day Wagtail may add a conflicting field toPagethus interfering withwagtail-modeltranslation.Wagtail’sslugurltag does not work across languages.wagtail-modeltranslationprovides a drop-in replacement namedslugurl_transwhich by default takes the slug parameter in the default language.Quick startInstallwagtail-modeltranslation:pip install wagtail-modeltranslationAdd ‘wagtail_modeltranslation’ to yourINSTALLED_APPSsetting like this (before all apps that you want to translate):INSTALLED_APPS = (
    ...
    'wagtail_modeltranslation',
    'wagtail_modeltranslation.makemigrations',
    'wagtail_modeltranslation.migrate',
)Add ‘django.middleware.locale.LocaleMiddleware’ toMIDDLEWAREon yoursettings.py:MIDDLEWARE = (
    ...
    'django.middleware.locale.LocaleMiddleware',  # should be after SessionMiddleware and before CommonMiddleware
)Enable i18n onsettings.py:USE_I18N = TrueDefine available languages onsettings.py:from django.utils.translation import gettext_lazy as _

LANGUAGES = (
    ('pt', _('Portuguese')),
    ('es', _('Spanish')),
    ('fr', _('French')),
)Createtranslation.pyinside 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',
    )Runpython manage.py makemigrationsfollowed bypython manage.py migrate(repeat every time you add a new language or register a new model)Runpython manage.py sync_page_translation_fields(repeat every time you add a new language)If you’re addingwagtail-modeltranslationto an existing site runpython manage.py update_translation_fieldsSupported versionsTitlewagtail-modeltranslation releaseCompatible Wagtail versionsCompatible Django versionsCompatible Python versions0.10>= 1.12, < 2.12>= 1.112.7, 3.4, 3.5, 3.60.11>= 2.13, < 3.0>= 3.03.6, 3.7, 3.8, 3.90.12>= 3.0, < 4.0>= 3.23.7, 3.8, 3.9, 3.100.13>= 4.0, < 5.0>= 3.23.7, 3.8, 3.9, 3.100.14>= 5.0>= 3.23.8, 3.9, 3.10, 3.11Upgrade considerations (v0.10.8)Template tagchange_langnow needs a second parameter,pageUpgrade considerations (v0.8)This version includes breaking changes as some key parts of the app have been re-written:The most important change is thatPageis now patched with translation fields.WAGTAILMODELTRANSLATION_ORIGINAL_SLUG_LANGUAGEsetting has been deprecated.To upgrade to this version you need to:Replace theWagtailTranslationOptionswithTranslationOptionsin all translation.py filesRunpython manage.py sync_page_translation_fieldsat least once to createPage’s translation fieldsReplace any usages of Wagtail’s{% slugurl ... %}forwagtail-modeltranslation’s own{% slugurl_trans ... %}While optional it’s recommended to add'wagtail_modeltranslation.makemigrations'to your INSTALLED_APPS. This will override Django’smakemigrationscommand to avoid creating spuriousPagemigrations.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:WagtailTranslationOptionsMost of the changes are related to imports as they change from wagtail-modeltranslation to modeltranslation.To upgrade to this version you need to:Replace theTranslationOptionswithWagtailTranslationOptionsin all translation.py filesThe import of the register decorator is nowfrom modeltranslation.decorators import registerThe import of translator is nowfrom modeltranslation.translator import translatorProject Homehttps://github.com/infoportugal/wagtail-modeltranslationDocumentationhttp://wagtail-modeltranslation.readthedocs.io/