Page translation plugin for Wagtail
A plugin for Wagtail that provides page translations. By extending your pages with the models included in this package users will be redirected to pages in (or closest to) their language.
Install using pip:
$ pip install wagtailtranslations
Add it to your INSTALLED_APPS:
INSTALLED_APPS = [ # ... 'wagtailtranslations', # ... ]
It works with Wagtail 2.2 and upwards. Check versions before 2.0 for compatability with older versions of wagtail.
Define a TranslationIndex model:
from wagtailtranslations.models import AbstractTranslationIndexPage class TranslationHomePage(AbstractTranslationIndexPage): subpage_types = ['ContentPage']
Use this as your site root page. Each language your site supports should exist as a separate page tree underneath this index page. The English home page should have a slug “en”, for a URL of /en/; while the French home page should have a slug “fr”, for a URL of /fr/.
Define a translated model:
from wagtail.admin.edit_handlers import FieldPanel from wagtail.core.fields import RichTextField from wagtail.core.models import Page from wagtailtranslations.models import TranslatedPage class ContentPage(TranslatedPage, Page): body = RichTextField() content_panels = Page.content_panels + [ FieldPanel('body'), ]
Enable some languages in the Wagtail admin → Settings → Languages, for example English and French.
Create a new ContentPage for English. On the ‘Translations’ tab, select English for the language, and leave the ‘Translation of …’ field blank.
Create another new ContentPage for French. On the ‘Translations’ tab, select French for the language, and select the English page you just created in the ‘Translation of …’ field.
To start a test server, run:
$ python3 -m venv venv $ source venv/bin/activate $ pip install -e . $ export DJANGO_SETTINGS_MODULE=tests.settings $ django-admin migrate $ django-admin createsuperuser $ django-admin runserver
To run the automated test suite:
# Do not run this from within a virtual environment $ pip install --user --upgrade tox pip setuptools $ tox
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|wagtailtranslations-2.0.0-py3-none-any.whl (11.4 kB) Copy SHA256 hash SHA256||Wheel||3.6|
|wagtailtranslations-2.0.0.tar.gz (10.1 kB) Copy SHA256 hash SHA256||Source||None|