Skip to content

Commit

Permalink
Update Wagtail/ Smartling integration on the Bedrock side (#14935)
Browse files Browse the repository at this point in the history
* Fix inappropriate notification about snitch pinging - should only happen if there's a Snitch URL configured

* Prevent wagtail-localize translating the slug field of any page that uses our base class

Instead, it will keep it synchronised with the value of the slug in the source page.

This means that we won't get slugs sent to Smartling for translation, either - we don't want that, based on what we've done so far in Bedrock

* Extend list of languages we'll initially localize via Smartling and the CMS

Note that the settings here will require the 0.2.4 release of wagtail-localize-smartling (or greater)
  • Loading branch information
stevejalim authored Aug 30, 2024
1 parent 1447d33 commit 15115fe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bedrock/cms/management/commands/run_smartling_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def handle(self, *args, **kwargs):
)
if SMARTLING_SYNC_SNITCH_URL:
requests.get(SMARTLING_SYNC_SNITCH_URL)
sys.stdout.write("Snitch pinged\n")
sys.stdout.write("Snitch pinged\n")
except Exception as ex:
sys.stderr.write(f"\nsync_smartling did not execute successfully: {ex}\n")
8 changes: 8 additions & 0 deletions bedrock/cms/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.views.decorators.cache import never_cache

from wagtail.models import Page as WagtailBasePage
from wagtail_localize.fields import SynchronizedField

from lib import l10n_utils

Expand All @@ -32,6 +33,13 @@ class AbstractBedrockCMSPage(WagtailBasePage):
`serve_password_required_response` method, via the @method_decorator above
"""

# Make the `slug` field 'synchronised', so it automatically gets copied over to
# every localized variant of the page and shouldn't get sent for translation.
# See https://wagtail-localize.org/stable/how-to/field-configuration/
override_translatable_fields = [
SynchronizedField("slug"),
]

class Meta:
abstract = True

Expand Down
33 changes: 25 additions & 8 deletions bedrock/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,14 +2101,21 @@ def before_send(event, hint):

def lazy_wagtail_langs():
enabled_wagtail_langs = [
("en-US", "English"),
# TODO: expand to other locales supported by our translation vendor
# ("de", "Deutsch"),
("fr", "Français"),
# ("es", "Español"),
# ("es", "Español mexicano"),
# ("it", "Italiano"),
# more to come
# Notes:
# 1) The labels are only used internally so can be in English
# 2) These are the Bedrock-side lang codes. They are mapped to
# Smartling-specific ones in the WAGTAIL_LOCALIZE_SMARTLING settings, below
("en-US", "English (US)"),
("de", "German"),
("fr", "French"),
("es-ES", "Spanish (Spain)"),
("it", "Italian"),
("ja", "Japanese"),
("nl", "Dutch (Netherlands)"),
("pl", "Polish"),
("pt-BR", "Portuguese (Brazil)"),
("ru", "Russian"),
("zh-CN", "Chinese (China-Simplified)"),
]
enabled_language_codes = [x[0] for x in LANGUAGES]
retval = [wagtail_lang for wagtail_lang in enabled_wagtail_langs if wagtail_lang[0] in enabled_language_codes]
Expand Down Expand Up @@ -2144,6 +2151,16 @@ def lazy_wagtail_langs():
default="5",
parser=float,
), # Timeout in seconds for requests to the Smartling API
"LOCALE_TO_SMARTLING_LOCALE": {
"de": "de-DE",
"fr": "fr-FR",
"it": "it-IT",
"ja": "ja-JP",
"nl": "nl-NL",
"pl": "pl-PL",
"ru": "ru-RU",
},
"REFORMAT_LANGUAGE_CODES": False, # don't force language codes into Django's all-lowercase pattern
}

# Custom settings, not a core Wagtail ones, to scope out RichText options
Expand Down

0 comments on commit 15115fe

Please sign in to comment.