Skip to content
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

Language selector on CMS pages is showing too many languages #15037

Closed
Tracked by #14225
stevejalim opened this issue Aug 30, 2024 · 6 comments · Fixed by #15062
Closed
Tracked by #14225

Language selector on CMS pages is showing too many languages #15037

stevejalim opened this issue Aug 30, 2024 · 6 comments · Fixed by #15062
Assignees
Labels
Backend Server stuff yo Bug 🐛 Something's not working the way it should L10N P2 Second level priority - Should have

Comments

@stevejalim
Copy link
Collaborator

stevejalim commented Aug 30, 2024

As we'll see when #14801 lands, there's currently a niggle where a page that intended for just one locale has all the other CMS-supported langages available in the language picker in the footer.

This may be a bug in the integration of the lang picker or it may just be that Wagtail is creating aliases of a the en-US page in all the other available locales and we don't want that.

Need investigation and is a blocker for turning on the CMS-backed leadership page in prod, so P2

@stevejalim stevejalim added Bug 🐛 Something's not working the way it should L10N Backend Server stuff yo P2 Second level priority - Should have labels Aug 30, 2024
@stevejalim
Copy link
Collaborator Author

cc @alexgibson for awareness

@janbrasna
Copy link
Contributor

it's drawn from translations context that's being defined here on the render() for CMS pages:

if is_cms_page and request._locales_available_via_cms:
translations = request._locales_available_via_cms

so it's patched as:

def _patch_request_for_bedrock(self, request):
# Add hints that help us integrate CMS pages with core Bedrock logic
request.is_cms_page = True
request._locales_available_via_cms = [self.locale.language_code] + [x.locale.language_code for x in self.get_translations()]

to get the translations from get_translations() — they must be coming wrong from it already.

@stevejalim
Copy link
Collaborator Author

stevejalim commented Aug 30, 2024

yeah, poking around lightly i can see that my local build has other locale versions of the test page i intended to be in en-US only, but saved as draft. So, two things there:

  1. I didn't expect (or want) wagtail-loalize to auto-create versions of my test page in other locales - i would expect that only to happen if i hit 'translate this page', so that needs exploring - one that I will raise in the Wagtail Slack if I can't find docs about it

  2. Looks like get_translations doesn't take into consideration whether a page is live or not:

https://github.com/wagtail/wagtail/blob/4af8ab528bc4439a3deb50b30d61324eb18871ed/wagtail/models/i18n.py#L287-L298

so we might be able to change things like this to skip the drafts, which is an important fix anyway, plus limit it to public (rather than password-protected) pages, too:

-      ... [x.locale.language_code for x in self.get_translations()] 
+      ... [x.locale.language_code for x in self.get_translations().live().public()]

@stevejalim
Copy link
Collaborator Author

Ah, I've got it - the other pages are live and public, but they're also auto-generated aliases of the page in question.

So I think we need to

  1. def disable that auto-creation of aliases
  2. to be extra sure, exclude aliased pages from the query used to get the relevant languages

@stevejalim
Copy link
Collaborator Author

@alexgibson I'd hold off merging (or at least trying to set up) #14801 till this is done in case we need to replumb anything

@stevejalim
Copy link
Collaborator Author

stevejalim commented Sep 2, 2024

Moving the issues with auto-creation of alias pages to a separate ticket: #15063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Server stuff yo Bug 🐛 Something's not working the way it should L10N P2 Second level priority - Should have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants