Skip to main content

Page translation plugin for Wagtail

Project description

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.

Installing

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.

Quick start

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.

Testing

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtailtranslations-2.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

wagtailtranslations-2.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file wagtailtranslations-2.0.0.tar.gz.

File metadata

  • Download URL: wagtailtranslations-2.0.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for wagtailtranslations-2.0.0.tar.gz
Algorithm Hash digest
SHA256 840f143558a4118d1cc379b2fb2e4460d7a09eecc4a93b51d8fe22231a08f509
MD5 343abbcd401dd0bc69d051d9eeb468d1
BLAKE2b-256 e8899ea804e19ab763fcfb9178062108dc22dd67c37b75736943172550d179a2

See more details on using hashes here.

File details

Details for the file wagtailtranslations-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtailtranslations-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6753bb35d8ef57c742390fe826b5864217d6fbafeceb044e5c27faec6296cd1c
MD5 088c7946e22f3b659f362077a1c5073a
BLAKE2b-256 8dcdbcdd79bac061832be55c09f42005166c4d2a0aafd9dd00fdb15b7dc7df74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page