Installation

Requirements

  • Wagtail >= 1.12

Installing using Pip

$ pip install wagtail-modeltranslation

Installing using the source

Quick Setup

To setup the application please follow these steps:

  1. In your settings file:

    • Add ‘wagtail_modeltranslation’ to INSTALLED_APPS

      INSTALLED_APPS = (
          ...
          'wagtail_modeltranslation',
          'wagtail_modeltranslation.makemigrations',
          'wagtail_modeltranslation.migrate',
      )
      
    • Add ‘django.middleware.locale.LocaleMiddleware’ to MIDDLEWARE (MIDDLEWARE_CLASSES before django 1.10).

      MIDDLEWARE = (
          ...
          'django.middleware.locale.LocaleMiddleware',  # should be after SessionMiddleware and before CommonMiddleware
      )
      
    • Set USE_I18N = True

  • Configure your LANGUAGES setting.

    The LANGUAGES variable must contain all languages you will use for translation. The first language is treated as the default language.

    Modeltranslation uses the list of languages to add localized fields to the models registered for translation. For example, to use the languages Portuguese, Spanish and French in your project, set the LANGUAGES variable like this (where pt is the default language). In required fields the one for the default language is marked as required (for more advanced usage check django-modeltranslation required_languages.)

    Warning

    When the LANGUAGES setting isn’t present in settings.py (and neither is MODELTRANSLATION_LANGUAGES), it defaults to Django’s global LANGUAGES setting instead, and there are quite a few languages in the default!

Note

To learn more about preparing Wagtail for Internationalisation check the Wagtail i18n docs.

  1. Create a translation.py file in your app directory and register TranslationOptions for every model you want to translate and for all subclasses of Page model.

    from .models import foo
    from modeltranslation.translator import TranslationOptions
    from modeltranslation.decorators import register
    
    @register(foo)
    class FooTR(TranslationOptions):
        fields = (
           'body',
        )
    
  2. Run python manage.py makemigrations followed by python manage.py migrate. This will add the tranlation fields to the database, repeat every time you add a new language or register a new model.

  3. Run python manage.py sync_page_translation_fields. This will add translation fields to Wagtail’s Page table, repeat every time you add a new language.

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

  5. Define the panels for the original fields, as you normally would, as wagtail-modeltranslation will generate the panels for the translated fields.