Configure the plugin in your Django settings:
WAGTAIL_LOCALIZE_SMARTLING = {
"PROJECT_ID": "<project_id>",
"USER_IDENTIFIER": "<user_identifier>",
"USER_SECRET": "<user_secret>",
"REQUIRED": False,
"ENVIRONMENT": "production",
"API_TIMEOUT_SECONDS": 5.0,
}
If your project's locales do not match those in Smartling (e.g. ro
in your
project, ro-RO
in Smartling), then you can provide a Wagtail locale ID to
Smartling locale ID mapping via the LOCALE_TO_SMARTLING_LOCALE
setting:
WAGTAIL_LOCALIZE_SMARTLING = {
"LOCALE_TO_SMARTLING_LOCALE": {
"ro": "ro-RO"
}
}
... or you can specify a callable or a dotted path to a callable in the
LOCALE_MAPPING_CALLBACK
setting:
def map_project_locale_to_smartling(locale: str) -> str:
if locale == "ro":
return "ro-RO"
return locale
WAGTAIL_LOCALIZE_SMARTLING = {
"LOCALE_MAPPING_CALLBACK": "settings.map_project_locale_to_smartling"
}
The callback receives a WAGTAIL_CONTENT_LANGUAGES
locale code string and is
expected to return a valid mapped locale ID (or the original locale ID).
Note that by default, when syncing translations the project will attempt to
reformat a mixed-case, Smartling-style language code (e.g. zh-CN
) into a
Django-style all-lowercase code (e.g. zh-cn
). Depending on how language
codes are set up in your project, this behaviour may not be appropriate. You
can disable it by settings the REFORMAT_LANGUAGE_CODES
setting to False
(the default is True
):
WAGTAIL_LOCALIZE_SMARTLING = {
"REFORMAT_LANGUAGE_CODES": False
}
If you need to customize the default Job description, you can specify a callable or a dotted path to a callable in
the JOB_DESCRIPTION_CALLBACK
setting:
from typing import Iterable
from wagtail_localize.models import Translation, TranslationSource
def enhance_job_description(
description: str,
translation_source: TranslationSource,
translations: Iterable[Translation]
) -> str:
return description + " my text."
The callback receives the default description string, the job TranslationSource
instance, and the list of
target Translation
s. It expected to return string.
If you want to pass a Visual Context
to Smartling after a Job is synced, you need to provide a way to get hold
of the appropriate URL for the page to use context. You provide this via
the VISUAL_CONTEXT_CALLBACK
setting.
If this callback is defined, it will be used to send the visual context to Smartling.
This step happens just after the regular sync of a Job to Smartling and only if
the callback is defined.
The callback must take the Job instance and return:
- a URL for the page that shows the content used to generate that Job
- the HTML of the page.
from wagtail.models import Page
from wagtail_localize.models import Job
from wagtail_localize_smartling.exceptions import IncapableVisualContextCallback
def get_visual_context(job: Job) -> tuple[str, str]:
content_obj = job.translation_source.get_source_instance()
if not isinstance(content_obj, Page):
raise IncapableVisualContextCallback(
"Object was not visually previewable"
)
page_url = page.full_url
html =
return page_url, html
Note that if the syncing of the visual context fails, this will break the
overall sync to Smartling, leaving an inconsistent state:
there'll be a Job created in Smartling that's awaiting approval, but Wagtail
will still think the job needs to be created. This, in turn, will mean we get
duplicate job errors on the retry. Therefore, it is essential you have log
handling set up to catch the ERROR
-level alert that will happen at this point.
By default, when translations for completed Jobs are imported into Wagtail,
the system will send notification emails to anyone in the Translation approver
Group, and also add a task list of items to (re)publish. You can disable these via
the settings:
SEND_EMAIL_ON_TRANSLATION_IMPORT
andADD_APPROVAL_TASK_TO_DASHBOARD
respectively.
The name of the Translation approver
group is also a setting:
TRANSLATION_APPROVER_GROUP_NAME
, but be careful about changing
this after the first deployment, as a data migration bootstraps the Group.
You can also control how many tasks are shown on the dashboard
via the MAX_APPROVAL_TASKS_ON_DASHBOARD
setting.