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.
For multilingual websites, the recommended packages are Wagtail Localize or Wagtail Simple Translation. 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 and works in combination with Simple Translation, offering the ideal solution for projects seeking a simple interface with powerful translation support.
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"
Customise Wagtail Translate
See: docs/customise_wagtail_translate.md.
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
Built Distribution
File details
Details for the file wagtail_translate-0.2.0.tar.gz
.
File metadata
- Download URL: wagtail_translate-0.2.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e91ac4a38c152b8ab648cf08cd02fc341df0a3a2ca48f490fdd0a59438277ba |
|
MD5 | 81e41fac7d595bf8c1a881d8e5ec0e6c |
|
BLAKE2b-256 | 9fc7148ebdfecac8e4ce5d0a83441b8d9fd9bdd38137daa14198a92cd4e986c4 |
File details
Details for the file wagtail_translate-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: wagtail_translate-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d95642597ea837943ba6f94e925e442f359e97cea3321b3fcb872e72d446b06 |
|
MD5 | 28475d0bde59b3d7b2ee694f08dcdc76 |
|
BLAKE2b-256 | fa33ed7588e62ebf29f5f1ed612e5ff2d9c3191b3d96fb4e57ff857443629911 |