-
Notifications
You must be signed in to change notification settings - Fork 913
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
Fix root global page active locales #15025
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15025 +/- ##
==========================================
+ Coverage 77.64% 77.68% +0.04%
==========================================
Files 162 162
Lines 8341 8359 +18
==========================================
+ Hits 6476 6494 +18
Misses 1865 1865 ☔ View full report in Codecov by Sentry. |
# first resource is the one to check for activation | ||
return get_active_locales(self.resource_ids[0]) | ||
|
||
@cached_property | ||
def active_home_locales(self): | ||
# use mozorg/home to check for activation | ||
return get_active_locales("mozorg/home.ftl") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, umm, instead of butchering the getter above it (potentially affecting gazillion page hits), it felt safer to just add a new one, doing just this one job checking for homepage languages separately, and using that in addition for the is_root condition. Maybe stupid, take this as more of a pseudo-code @stevejalim, and tear it apart as you see fit.
The hardcoded path string feels somewhat fragile here. Is there a better way?
(Also, some clever tests to cover the root specifics?)
translations = l10n.active_locales if not is_root_path_with_no_language_clues(request) else l10n.active_home_locales | ||
allowed = settings.PROD_LANGUAGES if not settings.DEV else settings.DEV_LANGUAGES | ||
translations = set(translations).intersection(allowed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to pick a place where to allow only approved locales among all the layers it travels through… but it seemed the least intrusive to just do it here, after getting stuff from either context or l10n instance, and also before adding any extra locales in case the extras are intentionally outside of the allowed range, not filtering them out later. Also, not filtering if the language list comes from other source as CMS translations or activation files (=keeping most of the current logic intact and only making changes that may ever impact the is_root case).
One-line summary
Shows only applicable languages for navigating to the home page on global
/
root.Significant changes and points to review
/
locale choice root listsactive_locales
based either on its own view (404 in fact) language files, or more likely because the metadata checks coincidentally use the first locale file in the folder and the404.ftl
comes first. But the properactive_locales
for homepage have to be read frommozorg/home.ftl
instead.Issue / Bugzilla link
Fixes #15010
Testing
(in prod mode, with Dev=False for restricted languages & Debug=False as the root is 404)
http://localhost:8000/ (with Accept-Locale empty)