-
Notifications
You must be signed in to change notification settings - Fork 966
WT-997: l10n tech parity with Springfield (alias locales, package upgrades) #17133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stevejalim
wants to merge
28
commits into
mozilla:main
Choose a base branch
from
stevejalim:WT-997--l10n-tech-parity-with-springfield
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
13c0e04
Upgrade wagtail-localize-smartling and -dashboard; add zh-CN LANG_INF…
stevejalim bbace8d
Add alias locale transparent serving (pt-PT, en-GB, en-CA)
stevejalim 042efbf
Fix page.localized and URLs for alias locales (port Springfield f50d3…
stevejalim 30b4e9f
Merge branch 'main' into WT-997--l10n-tech-parity-with-springfield
stevejalim a9e4b32
Add es-CL, es-MX to WAGTAIL_CONTENT_LANGUAGES; fix EXCLUDE_LOCALES va…
stevejalim 82fa9cd
fix failing tests by correctly adding es-AR as a wagtail lang
stevejalim 60486d3
populate _content_locales_via_cms for requests, so it can be used to …
dchukhin 11b2a24
set up content_locales and alias fallback for non-Wagtail pages
dchukhin c00fa8b
add CANONICAL_LANG to page context
dchukhin 12291db
update templates to correctly set canonical URL, noindex, and hreflan…
dchukhin f42f9be
explicitly set SQLITE_EXPORT_MODE when running db export
dchukhin 970d1a7
bundle the admin badge JS like in springfield
dchukhin 6b6dd41
add unit tests for new code that is missing test coverage
dchukhin 1a0a997
add unit tests for fallback scenarios on a prefer_cms() view
dchukhin 804c4f1
auto-exclude alias locales from smartling sync
dchukhin 201d211
Merge branch 'main' into WT-997--l10n-tech-parity-with-springfield
dchukhin 97f747f
add template for newly-added tests
dchukhin a60f35b
make sure alias locales show up in language picker for static pages i…
dchukhin dd0e950
set up es-MX as an alias locale to fall back to es-ES
dchukhin 97f0095
make sure es-MX exists as a locale in Wagtail
dchukhin 712e7e5
update tests to not use es-MX as a fallback locale (since it is an al…
dchukhin b6e8061
update comment to not refer to es-MX as a fallback locale (since it i…
dchukhin bb3b483
Merge branch 'main' into WT-997--l10n-tech-parity-with-springfield
dchukhin e822faa
Merge branch 'main' into WT-997--l10n-tech-parity-with-springfield
stevejalim 777706d
make sure that fallback Page content is served for alias locales when…
dchukhin 04b2530
show canonical tag even if a page is not indexed
dchukhin ae218ea
Merge branch 'main' into WT-997--l10n-tech-parity-with-springfield
dchukhin a570ecb
Merge branch 'main' into WT-997--l10n-tech-parity-with-springfield
stevejalim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
bedrock/cms/migrations/0005_create_alias_locale_records.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| import sys | ||
|
|
||
| from django.db import migrations | ||
|
|
||
| from bedrock.base.config_manager import config | ||
|
|
||
|
|
||
| def create_alias_locales(apps, schema_editor): | ||
| # Skip in test environments — test fixtures create the locale records they need. | ||
| if "pytest" in sys.modules or config("SQLITE_EXPORT_MODE", parser=bool, default="false"): | ||
| return | ||
|
|
||
| from wagtail.models import Locale, Page, Site | ||
|
|
||
| alias_locales = ["es-AR", "es-CL", "pt-PT", "en-GB", "en-CA"] | ||
|
|
||
| site = Site.objects.filter(is_default_site=True).select_related("root_page").first() | ||
| if not site: | ||
| return | ||
|
|
||
| # The locale root pages live at depth 2 (children of the Wagtail tree | ||
| # root at depth 1). Note: site.root_page is the *homepage* (depth 3), | ||
| # not the locale root — using it would place new pages one level too deep. | ||
| en_us_locale_root = Page.objects.filter( | ||
| depth=2, | ||
| locale__language_code="en-US", | ||
| ).first() | ||
| if not en_us_locale_root: | ||
| return | ||
| wagtail_root = en_us_locale_root.get_parent() | ||
|
|
||
| for code in alias_locales: | ||
| locale, _ = Locale.objects.get_or_create(language_code=code) | ||
|
|
||
| if en_us_locale_root.get_translation_or_none(locale) is not None: | ||
| continue | ||
|
|
||
| # Create a non-live locale root page for the alias locale at depth 2, | ||
| # alongside the other locale roots (de, fr, es-ES, etc.). | ||
| # | ||
| # We use copy() rather than copy_for_translation() because the Wagtail | ||
| # tree root (depth 1) has no per-locale translations, which causes | ||
| # copy_for_translation()'s parent-translation check to fail. | ||
| # | ||
| # keep_live=False ensures Wagtail won't serve this page at | ||
| # /<alias-locale>/ — the fallback machinery | ||
| # (wagtail_serve_with_locale_fallback + find_fallback_page_for_locale) | ||
| # handles those requests and serves the canonical locale's content. | ||
| # The root page is a structural record; the fallback machinery | ||
| # does not require it to exist. | ||
| en_us_locale_root.copy( | ||
| to=wagtail_root, | ||
| update_attrs={ | ||
| "locale": locale, | ||
| "slug": f"home-{code}", | ||
| }, | ||
| copy_revisions=False, | ||
| keep_live=False, | ||
| reset_translation_key=False, | ||
| log_action=None, | ||
| ) | ||
|
|
||
|
|
||
| def remove_alias_locales(apps, schema_editor): | ||
| if "pytest" in sys.modules or config("SQLITE_EXPORT_MODE", parser=bool, default="false"): | ||
| return | ||
|
|
||
| from wagtail.models import Locale, Page | ||
|
|
||
| alias_locales = ["es-AR", "es-CL", "pt-PT", "en-GB", "en-CA"] | ||
|
|
||
| en_us_locale_root = Page.objects.filter( | ||
| depth=2, | ||
| locale__language_code="en-US", | ||
| ).first() | ||
| if not en_us_locale_root: | ||
| return | ||
|
|
||
| for code in alias_locales: | ||
| locale = Locale.objects.filter(language_code=code).first() | ||
| if not locale: | ||
| continue | ||
|
|
||
| # Delete the locale root page only if it has no child pages | ||
| # (i.e. the alias locale was never promoted to a full locale with its own content). | ||
| alias_root = en_us_locale_root.get_translation_or_none(locale) | ||
| if alias_root is not None and not alias_root.get_children().exists(): | ||
| alias_root.delete() | ||
|
|
||
| # Delete the Locale record if no pages remain under it. | ||
| if not Page.objects.filter(locale=locale).exists(): | ||
| locale.delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("cms", "0004_bedrocklocale"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(create_alias_locales, remove_alias_locales), | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.