Installation

Requirements

  • Django >= 1.7
  • Wagtail >= 1.0

Installing using Pip

$ pip install wagtail-modeltranslation >= 0.2.2

Installing using the source

Setup

To setup the application please follow these steps:

  1. In the settings/base.py file:

    • Add wagtail_modeltranslation to the INSTALLED_APPS
    INSTALLED_APPS = (
     ...
    'wagtail_modeltranslation',
     )
    
    • Add django.middleware.locale.LocaleMiddleware to MIDDLEWARE_CLASSES.
    MIDDLEWARE_CLASSES = (
    ...
    
    'django.middleware.locale.LocaleMiddleware',
    )
    
    • Set USE_I18N = True
  • Configure your LANGUAGES.

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

    LANGUAGES = (
       ('pt', u'Portugese'),
       ('es', u'Spanish'),
       ('fr', u'French'),
     )
    

Warning

When the LANGUAGES setting isn’t present in settings/base.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!

  1. Create a translation.py file in your app directory and register TranslationOptions for every model you want to translate.
from .models import foo
from wagtail_modeltranslation.translation import TranslationOptions
from wagtail_modeltranslation.decorators import register

@register(foo)
class FooTR(TranslationOptions):
    fields = (
       'body',
    )
  1. Add TranslationMixin to your translatable model:.
# .models foo
...
from wagtail_modeltranslation.models import TranslationMixin

class FooModel(TranslationMixin, Page):
    body = StreamField(...)
  1. Run python manage.py makemigrations followed by python manage.py migrate. This will add extra fields in the database.