Installation¶
Requirements¶
- Django >= 1.7
- Wagtail >= 1.0
Installing using Pip¶
$ pip install wagtail-modeltranslation >= 0.2.2
Installing using the source¶
From github: git clone https://github.com/infoportugal/wagtail-modeltranslation.git
- Copy wagtail_modeltranslation folder in project tree
OR
Download ZIP file on Github.com from infoportugal/wagtail-modeltranslation
- Unzip and copy wagtail_modeltranslation folder in project tree
Setup¶
To setup the application please follow these steps:
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
ptis 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!
- Create a
translation.pyfile in your app directory and registerTranslationOptionsfor 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',
)
- Add
TranslationMixinto your translatable model:.
# .models foo
...
from wagtail_modeltranslation.models import TranslationMixin
class FooModel(TranslationMixin, Page):
body = StreamField(...)
- Run
python manage.py makemigrationsfollowed bypython manage.py migrate. This will add extra fields in the database.