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

Ensure view gets a locale #6503

Merged
merged 2 commits into from
Feb 12, 2025
Merged

Conversation

smithellis
Copy link
Contributor

In the case of leaving the revision page, then returning via the browser back button, the locale wasn't being set in any way. This change ensures the locale is set.

This should resolve mozilla/sumo#2018

@@ -1697,10 +1697,10 @@ def recent_revisions(request):
form.is_valid()

filters = {}
locale = None
Copy link
Contributor

@escattone escattone Feb 11, 2025

Choose a reason for hiding this comment

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

Why is this needed? It's never set to anything else other than None and then ignored below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correcting.

@@ -1717,7 +1717,7 @@ def recent_revisions(request):
c = {
"revisions": revs,
"form": form,
"locale": request.GET.get("locale", request.LANGUAGE_CODE),
"locale": locale or request.LANGUAGE_CODE, # Ensure locale is always set
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this change as well. Why are you no longer getting the locale from the URL's query parameters?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What basically this does is equivalent to "locale": request.LANGUAGE_CODE. You are setting locale=None which will force the short circuit operation to evaluate always to request.LANGUAGE_CODE

The problem here is the get() method. It defaults to request.LANGUAGE_CODE if the "locale" dictionary key is not present. It doesn't check the value of the key which is the empty string.

This should be:

"locale": request.GET.get("locale") or request.LANGUAGE_CODE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right of course; correcting.

Copy link
Collaborator

@akatsoulas akatsoulas left a comment

Choose a reason for hiding this comment

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

Please merge after the release.

@akatsoulas akatsoulas merged commit 0d4b981 into mozilla:main Feb 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants