Translate and localize Wagtail CMS content with RWS LanguageCloud
Project description
Wagtail Localize RWS LanguageCloud
This allows users of RWS LanguageCloud to translate and localize Wagtail CMS content.
Requirements
- Python >= 3.7
- Django >= 3.0
- Wagtail >= 2.12
- wagtail-localize >= 1.0.1
Setup
-
pip install wagtail-localize-rws-languagecloud
-
Add
wagtail_localize_rws_languagecloud
toINSTALLED_APPS
beforewagtail.admin
andwagtail_localize
:INSTALLED_APPS = [ # ... "wagtail_localize_rws_languagecloud", "wagtail.admin", "wagtail_localize", ]
-
Configure the plugin in Django settings:
import datetime WAGTAILLOCALIZE_RWS_LANGUAGECLOUD = { # (required) Authentication details to connect to the LanguageCloud API. # For info on how to obtain these credentials see https://languagecloud.sdl.com/lc/api-docs/authenticate "CLIENT_ID": "<client id>", "CLIENT_SECRET": "<client secret>", "ACCOUNT_ID": "<account id>", # (required) Identifier of a LanguageCloud template to create projects from "TEMPLATE_ID": "<template id>", # (required) Identifier of a LanguageCloud location to store project files in "LOCATION_ID": "<location id>", # (optional) Prefix for project names. Defaults to '' if not specified "PROJECT_PREFIX": "foobar_", # (optional) A timedelta object used to set the project 'due by' date. # Defaults to datetime.timedelta(days=7) if not specified "DUE_BY_DELTA": datetime.timedelta(days=30), # (optional) Number of a seconds to sleep between each API request. # Defaults to 0 if not specified "API_SLEEP_SECONDS": 5, # (optional) Send an email to uers with any of the following permissions: # - wagtail_localize.add_translation # - wagtail_localize.change_translation # - wagtail_localize.delete_translation # - wagtail_localize.submit_translation # when new translations are ready for review. # Defaults to False if not specified "SEND_EMAILS": True, # (optional) Provide a WAGTAIL_CONTENT_LANGUAGE code to RWS language code map # RWS expects region codes (e.g. "en-US", "de-DE") whereas Wagtail will happily # accept two letter lanugage code ("en", "de"). You can also use this mapping # to map dialect language codes to the main supported language "LANGUAGE_CODE_MAP": { "en": "en-US", "ja": "ja-JP", "es-mx": "es-ES", }, }
-
Apply migrations:
./manage.py migrate
Exporting and importing content to/from LanguageCloud
This plugin works by:
- Identifying text in Wagtail which is pending localization and exporting it to LanguageCloud
- Identifying completed projects in LanguageCloud and importing the localized content back into Wagtail
This is done through a management command:
./manage.py sync_rws
This command needs to be run on an interval using a scheduler like cron. We recommend an interval of about every 10 minutes.
It is desirable to prevent more than one copy of the sync command from running at the same time.
- If using cron as a scheduler, lockrun can be used to prevent multiple instance of the same job running simultaneously.
- If using a queue-based scheduler like Celery Beat, the
SyncManager
class containsis_queued
andis_running
extension points which could be used to implement a lock strategy.
Update translated pages
Wagtail Localize comes with a feature called "Sync translated pages" which copies untranslated content from the source page to its translated pages. This is useful when the source page content has been updated and needs to be copied and re-translated.
This plugin comes with an optional management command that automates this process by running sync translated pages on pages with stale translated content.
./manage.py update_translated_pages
This command:
- Runs "sync translated pages" on pages that have been published but not yet synced.
- Queues these pages to be translated on LanguageCloud using the default settings.
- Sends an email summary with the list of pages that were synced or skipped.
Pages that match the following criteria are excluded from auto-syncing:
- Pages that haven't been translated before.
- Pages that have pending translations on LanguageCloud.
You can use this command ad-hoc, or schedule it to run on an interval to automatically keep translated versions of your content up-to-date.
You can safely preview which pages will be affected without actually updating them by running the command with --dry-run
.
./manage.py update_translated_pages --dry-run
Signals
translation_imported
This signal is sent when a translation from RWS LanguageCloud is successfully imported.
Arguments:
- sender:
LanguageCloudProject
- instance: The specific
LanguageCloudProject
instance. - source_object: The page or snippet instance that this translation is for.
- translated_object: The translated instance of the page or snippet.
For more information on signal handlers, see the Django docs.
There are some more detailed examples of how the translation_imported
signal can be used to send slack notifications in slack-notification-examples.md.
How it works
This plugin uses wagtail-localize
to convert pages into segments and build new pages from translated segments. wagtail-localize
provides a web interface for translating these segments in Wagtail itself and this plugin plays nicely with that (translations can be made from the Wagtail side too).
Pages/snippets are submitted to LanguageCloud when they are submitted for translation from the default locale. Pages authored in other locales are not supported yet.
Contributing
All contributions are welcome!
Install
To make changes to this project, first clone this repository, then with your preferred virtualenv activated, install testing dependencies:
make install
pre-commit
Note that this project uses pre-commit. To set up locally:
# if you don't have it yet, globally
$ pip install pre-commit
# go to the project directory
$ cd wagtail-localize-rws-languagecloud
# initialize pre-commit
$ pre-commit install
# Optional, run all checks once for this, then the checks will run only on the changed files
$ pre-commit run --all-files
local_settings.py
You can add a local_settings.py
file next to settings.py
for any settings that you need when running the project locally.
For example, you might want to set a NAME
for the SQLite test database so that --keepdb
works.
# wagtail_localize_rws_languagecloud/test/local_settings.py
from .settings import DATABASES
DATABASES["default"]["TEST"] = {"NAME": "test.db"}
Project details
Release history Release notifications | RSS feed
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-localize-rws-languagecloud-0.8.1.tar.gz
.
File metadata
- Download URL: wagtail-localize-rws-languagecloud-0.8.1.tar.gz
- Upload date:
- Size: 49.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8049ef33312282cdb43d5826c1c81174be97859cc62dfdba4c9aafac592db055 |
|
MD5 | 5367dc30ee513fa7d9db38b3394b29be |
|
BLAKE2b-256 | e832bc4fb518940c83718152f23fabe35dec23b126eb544ea519eded0fe50eb7 |
File details
Details for the file wagtail_localize_rws_languagecloud-0.8.1-py3-none-any.whl
.
File metadata
- Download URL: wagtail_localize_rws_languagecloud-0.8.1-py3-none-any.whl
- Upload date:
- Size: 66.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f97f5e05cd82307e46ae5e5927ade6550ce83a7116f7618124a03fcbfa2415bb |
|
MD5 | cb0113230b686929734b34226445f3d1 |
|
BLAKE2b-256 | 46cccecde7fc113a251248c4cabdd6f17ed7fae1d96150dd5a0ea33d5e0d69ab |