Skip to content

WT-997: l10n tech parity with Springfield (alias locales, package upgrades)#17133

Open
stevejalim wants to merge 28 commits intomozilla:mainfrom
stevejalim:WT-997--l10n-tech-parity-with-springfield
Open

WT-997: l10n tech parity with Springfield (alias locales, package upgrades)#17133
stevejalim wants to merge 28 commits intomozilla:mainfrom
stevejalim:WT-997--l10n-tech-parity-with-springfield

Conversation

@stevejalim
Copy link
Copy Markdown
Contributor

Summary

Brings Bedrock's CMS l10n setup to parity with Springfield. Three areas of work:

  • Package upgrades: wagtail-localize-smartling 0.11.0 → 0.12.1, wagtail-localize-dashboard 0.1.2 → 0.3.0
  • zh-CN LANG_INFO fallback: adds LANG_INFO["zh-CN"] = {"fallback": ["zh-hans"]} to match Springfield, since zh-CN is in WAGTAIL_CONTENT_LANGUAGES but had no Django fallback defined
  • Alias locale transparent serving: ports Springfield's full alias locale mechanism so that e.g. /pt-PT/some/page/ transparently serves the pt-BR page at that URL without redirecting

Alias locales added

Alias Serves content from
pt-PT pt-BR
en-GB en-US
en-CA en-US

What was added / changed

New files:

  • bedrock/cms/views.pywagtail_serve_with_locale_fallback() intercepts alias locale requests before Wagtail and serves the fallback locale's page
  • bedrock/cms/wagtail_urls.py — replaces Wagtail's catch-all serve pattern with the above view
  • bedrock/cms/migrations/0005_create_alias_locale_records.py — creates non-live Locale + root page records for the three alias locales
  • media/js/cms/wagtailadmin-locale-badges.js — JS for the admin locale-list badges

Modified files:

  • bedrock/settings/base.pyFALLBACK_LOCALES dict; EXCLUDE_LOCALES in WAGTAIL_LOCALIZE_SMARTLING; zh-CN LANG_INFO fallback
  • bedrock/cms/utils.pyfind_fallback_page_for_locale() and compute_cms_page_locales() (language picker includes alias locales)
  • bedrock/cms/decorators.pyprefer_cms now calls wagtail_serve_with_locale_fallback instead of wagtail_serve directly
  • bedrock/urls.py — swaps in the custom wagtail_urls module
  • bedrock/cms/wagtail_hooks.py — admin badge hook marking alias locales on the locales list page
  • bedrock/cms/models/locale.pyBedrockLocale.get_active() checks FALLBACK_LOCALES before falling back to en-US (fixes page.localized resolving to en-US when alias locale has no DB record)
  • bedrock/cms/models/base.pyAbstractBedrockCMSPage.localized property resolves via fallback locale when the alias locale has no translation; get_active_locale_url() rewrites embedded page URLs to keep the alias locale prefix

Test plan

  • Run the test suite: pytest bedrock/cms/
  • Start a local dev server with WAGTAIL_ENABLE_ADMIN=true
  • In the Wagtail admin, go to Settings → Locales — confirm pt-PT, en-GB, en-CA appear with "alias →" badges next to their names
  • Publish a CMS page in pt-BR (e.g. a SimpleRichTextPage at /test-alias/)
  • Request /pt-PT/test-alias/ — confirm it returns 200 and renders the pt-BR content (not a redirect, not a 404)
  • Confirm the page URL shown in any links within the page uses /pt-PT/ not /pt-BR/
  • Request /en-GB/test-alias/ and /en-CA/test-alias/ for a page that exists in en-US — confirm transparent serving
  • Request a path that doesn't exist in pt-BR at a pt-PT URL — confirm 404 (not a 500)
  • Confirm pt-PT, en-GB, en-CA do not appear as available locales in the Smartling translation job UI (EXCLUDE_LOCALES)

…O fallback

- wagtail-localize-smartling: 0.11.0 → 0.12.1
- wagtail-localize-dashboard: 0.1.2 → 0.3.0
- Add LANG_INFO["zh-CN"] = {"fallback": ["zh-hans"]} to match Springfield,
  since zh-CN is in WAGTAIL_CONTENT_LANGUAGES but had no Django fallback defined
- Remove stale comment referencing non-existent bedrock.base.apps.BaseAppConfig
Ports Springfield's alias locale mechanism to Bedrock. Alias locales
transparently serve another locale's page content at their own URL prefix
without redirecting (e.g. /pt-PT/some/page/ serves the pt-BR page).

Three coordinated pieces:

- bedrock/cms/views.py: wagtail_serve_with_locale_fallback() — intercepts
  requests for alias locales before Wagtail and serves the fallback locale's
  page. Used by both the URL catch-all and prefer_cms.

- bedrock/cms/wagtail_urls.py: replaces Wagtail's catch-all serve pattern
  with wagtail_serve_with_locale_fallback.

- bedrock/cms/migrations/0005: data migration that creates non-live Locale +
  root page records for pt-PT, en-GB, en-CA so Wagtail is aware of them.

Supporting changes:

- FALLBACK_LOCALES setting (pt-PT→pt-BR, en-GB→en-US, en-CA→en-US)
- EXCLUDE_LOCALES added to WAGTAIL_LOCALIZE_SMARTLING (alias locales are
  not sent to Smartling as separate translation jobs)
- bedrock/cms/utils.py: add find_fallback_page_for_locale() and
  compute_cms_page_locales() (expands language picker to include alias locales)
- bedrock/cms/decorators.py: prefer_cms now calls
  wagtail_serve_with_locale_fallback instead of wagtail_serve directly
- bedrock/cms/wagtail_hooks.py: admin badge hook marking alias locales
  on the Wagtail locales list page
- media/js/cms/wagtailadmin-locale-badges.js: JS for the above hook
…f17)

When the active locale is an alias (e.g. pt-PT → pt-BR) that has no Locale
DB record or no page translation, two things were broken:

1. BedrockLocale.get_active() fell straight through to en-US instead of
   checking FALLBACK_LOCALES first — fixed by trying the fallback locale
   before giving up.

2. page.localized returned the en-US source page instead of the pt-BR
   translation — fixed by overriding localized on AbstractBedrockCMSPage
   to resolve via FALLBACK_LOCALES when the base class returns a
   wrong-locale result.

Also adds get_active_locale_url() so that page URLs embedded in templates
show the alias locale prefix (e.g. /pt-PT/...) rather than the canonical
fallback prefix (/pt-BR/...) when content is being served under an alias URL.
@stevejalim stevejalim requested review from a team as code owners April 13, 2026 14:07
…lidation

- Add en-GB, en-CA, es-CL, es-MX, pt-PT to lazy_wagtail_langs() so Wagtail
  is aware of them for routing (matching Springfield's approach)
- Merge FALLBACK_LOCALES into existing definition near CANONICAL_LOCALES;
  add es-AR, es-CL → es-ES aliases alongside pt-PT, en-GB, en-CA
- Add es-CL to EXCLUDE_LOCALES (alias locale, must not get Smartling jobs)
- Add es-CL to data migration 0005 so it gets a non-live locale root page
- Update test assertions to reflect alias locale expansion in
  compute_cms_page_locales (en-US pages now include en-GB, en-CA;
  pt-BR pages now include pt-PT)
@stevejalim stevejalim requested a review from dchukhin April 13, 2026 14:50
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 89.65517% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.87%. Comparing base (f87ea39) to head (a570ecb).

Files with missing lines Patch % Lines
bedrock/cms/utils.py 80.00% 7 Missing ⚠️
bedrock/cms/models/base.py 91.17% 3 Missing ⚠️
bedrock/cms/models/locale.py 75.00% 2 Missing ⚠️
bedrock/cms/views.py 95.45% 2 Missing ⚠️
bedrock/cms/wagtail_hooks.py 85.71% 2 Missing ⚠️
bedrock/cms/wagtail_urls.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17133      +/-   ##
==========================================
+ Coverage   81.76%   81.87%   +0.11%     
==========================================
  Files         175      177       +2     
  Lines        9381     9538     +157     
==========================================
+ Hits         7670     7809     +139     
- Misses       1711     1729      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@dchukhin dchukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like good changes. I made some comments and questions.

I added some missing code, and I tested this locally, and it seems to work as expected.

Comment thread bedrock/settings/base.py Outdated
Comment thread bedrock/cms/migrations/0005_create_alias_locale_records.py Outdated
Comment thread bedrock/settings/base.py
@stevejalim
Copy link
Copy Markdown
Contributor Author

@dchukhin Thanks for your work on this. Just do double-check, is this good to merge? if you or @maribedran can approve it, that'd be great. I made the PR so I can't approve it

@dchukhin
Copy link
Copy Markdown
Collaborator

I'd say "almost"!
I want to add the same changes as mozmeao/springfield#1292 here, and then it should be ready.

Copy link
Copy Markdown
Collaborator

@dchukhin dchukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@stevejalim
Copy link
Copy Markdown
Contributor Author

@dchukhin Thanks for the r+ -- i just noticed that this PR was made from my fork of bedrock - it's in sync with mozilla/bedrock but can we DM to just double-check alignment before I merge, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants