Skip to main content

Allows to translate specific pages without replicating all wagtail pages tree structure.

Project description

Wagtail pagetranslation

Allows to translate specific pages without replicating all wagtail pages tree structure.

License: MIT PyPI version pagetranslation CI

Links

Installation

  • python -m pip install wagtail-pagetranslation

How to use

Add "wagtail_pagetranslation" to list of applications after all wagtail apps

INSTALLED_APPS = [
    "your_wagtail_app_1",
    "your_wagtail_app_2",
    ...
    "wagtail_pagetranslation",
    ...
]

Set default language for wagtail_pagetranslation app

WAGTAIL_PAGETRANSLATION_DEFAULT_LANGUAGE = "en"

by default settings.LANGUAGES will be used

LANGUAGES = [
    ("en", "English"),
    ("nl", "Dutch"),
    ("uk", "Ukrainian")
]

or you can specify custom list

WAGTAIL_PAGETRANSLATION_LANGUAGES = [
    ("en", "English"),
    ("nl", "Dutch"),
    ("uk", "Ukrainian")
]

To make available translation per page type add TranslationMixin to your custom Page class. Note: mixin should be added before Page class.

from wagtail_pagetranslation.translation import TranslationMixin

class HomePage(TranslationMixin, Page):
    # list of fields that should have translation
    translatable_fields = ["title", ...]

By default URL for translated page is page url + ?lang=<lang_code> This can be change by overriding get_language method:

from wagtail_pagetranslation.translation import TranslationMixin as BaseTranslationMixin

class TranslationMixin(BaseTranslationMixin):
    # list of fields that should have translation
    translatable_fields = ["title", ...]

    def get_language(self, request):
        return request.GET.get("language")

Contributing

Install

To make changes to this project, first clone this repository:

git clone https://github.com/dest81/wagtail-pagetranslation.git
cd wagtail-pagetranslation

With your preferred virtualenv activated, install testing dependencies:

Using pip

python -m pip install --upgrade pip>=21.3
python -m pip install -e '.[testing]' -U

Using flit

python -m pip install flit
flit install

pre-commit

Note that this project uses pre-commit. It is included in the project testing requirements. To set up locally:

# go to the project directory
$ cd wagtail-pagetranslation
# initialize pre-commit
$ pre-commit install

# Optional, run all checks once for this, then the checks will run only on the changed files
$ git ls-files --others --cached --exclude-standard | xargs pre-commit run --files

How to run tests

Now you can run tests as shown below:

tox

or, you can run them for a specific environment tox -e python3.11-django4.2-wagtail5.1 or specific test tox -e python3.11-django4.2-wagtail5.1-sqlite wagtail-pagetranslation.tests.test_file.TestClass.test_method

To run the test app interactively, use tox -e interactive, visit http://127.0.0.1:8020/admin/ and log in with admin/changeme.

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

wagtail_pagetranslation-0.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

wagtail_pagetranslation-0.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_pagetranslation-0.0.1.tar.gz.

File metadata

File hashes

Hashes for wagtail_pagetranslation-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4197b1aca88e2e6b322dc22c060ee63d6e205f01ada2f9b36b18ea703d69737f
MD5 e126e6c7dd3689011c65987515f1e9ca
BLAKE2b-256 75a18b793e2b12670ab56cc9f5f5edafbf4903635dcb19e81058c9e7f0c419b2

See more details on using hashes here.

File details

Details for the file wagtail_pagetranslation-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_pagetranslation-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a4c70cb4a119a26d326c733b51f65da32472b99d40a0ec04ec9d9366dac9182
MD5 d7d2e5131f50935efc936125f3ac753f
BLAKE2b-256 d8649c386f4c083cf99800b274a6dc9b88dfb419c015385c1c7e71ceaba086d5

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