Skip to main content

Use Wagtail Translate to machine translate your Wagtail contents.

Project description

Wagtail Translate

Wagtail Translate adds machine translations to your Wagtail site, with built-in support for DeepL and the flexibility to integrate other translation services. It automatically detects when a page is copied to a new locale and initiates the translation process.

Wagtail Localize and Wagtail Simple Translation are the go-to solutions for multi-language Wagtail projects. Wagtail Localize offers advanced features that may be excessive for many projects, while Wagtail Simple Translation only copies pages to new locales, requiring manual translation.

Wagtail Translate adds machine translations to Wagtail. It works in combination with Simple Translation, offering the ideal solution for projects seeking a simple interface with powerful translation support.

License: MIT PyPI version Translate CI

Links

Supported versions

  • Python 3.8 - 3.12
  • Django 4.2 - 5.0
  • Wagtail 5.2 - 6.0

Internationalization

You need to configure your project for authoring content in multiple languages. See Wagtail documentation on internationalization.

In summary:

# settings.py
USE_I18N = True
WAGTAIL_I18N_ENABLED = True
USE_L10N = True

LANGUAGE_CODE = 'en'
WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
    (LANGUAGE_CODE, "English"),
    ('fr', "French"),
]

INSTALLED_APPS += [
    "wagtail.locales",
    "wagtail.contrib.simple_translation",
]

MIDDLEWARE += [
    'django.middleware.locale.LocaleMiddleware',
]

# urls.py
from django.conf.urls.i18n import i18n_patterns

urlpatterns += i18n_patterns(
    path("", include(wagtail_urls)),
)

Create the French locale at: /admin/locales/new/.

Installation

python -m pip install wagtail-translate
INSTALLED_APPS = [
    "wagtail_translate",
    "wagtail_translate.default_behaviour",
    ...
]

WAGTAIL_TRANSLATE_TRANSLATOR = "wagtail_translate.translators.rot13.ROT13Translator"

In the Wagtail admin interface, go to the homepage, in the dot-dot-dot-menu, choose "Translate".

The contents should be translated! 🥳

ROT13Translator

The installation example uses the ROT13Translator. It shifts each letter by 13 places. Applying it twice will return the text to its original form. ROT13 is good for testing and evaluation, but not for real-world use.

DeepLTranslator

Wagtail Translation has a DeepL translator. Install and configure it as follows:

  • pip install deepl
  • Get a DeepL API key from https://www.deepl.com/pro#developer
  • Add WAGTAIL_TRANSLATE_DEEPL_KEY = "..." to your settings.
  • Set WAGTAIL_TRANSLATE_TRANSLATOR = "wagtail_translate.translators.deepl.DeepLTranslator"

Documentation

Contributing

Install

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

git clone https://github.com/allcaps/wagtail-translate.git
cd wagtail-translate

With your preferred virtualenv activated, install testing dependencies:

Using pip

python -m pip install --upgrade pip
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-translate
# 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-translate.tests.test_file.TestClass.test_method

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

Project template

This project has been created with Cruft, a drop-in replacement for Cookiecutter.

cruft create git@github.com:wagtail/cookiecutter-wagtail-package.git

The "cookiecutter answers" are stored in .cruft.json. To update the project to the latest template, run:

cruft update

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_translate-0.3.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

wagtail_translate-0.3.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_translate-0.3.0.tar.gz.

File metadata

  • Download URL: wagtail_translate-0.3.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for wagtail_translate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 81d4de551e9dbd68e0473d77fdb6983885e45e69ee06a1316d2f1d11196248fc
MD5 f33f6aefc9119326b59cc341cd4011f2
BLAKE2b-256 d8645ec784b65ddfd2fd1ba08f3cb21d068ab74b4d9430f250343e21a186497b

See more details on using hashes here.

File details

Details for the file wagtail_translate-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_translate-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e64d4bf2e83cc3128de885c29be4f592379bdd39507cab00626292271c62f9f
MD5 ef42be624c2b058480272c58fa5a5c25
BLAKE2b-256 dfeaac4e08f8763448d09c03d5516584b1df728df9e7c9f79903f156b81ce9bf

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