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

feat(language-menu): add automatic redirect experiment #11518

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

caugner
Copy link
Contributor

@caugner caugner commented Jul 23, 2024

Summary

(MP-1242)

Fixes #275.
Fixes #2528.
Fixes #2724.
Fixes #6981.

Problem

  1. Search engines may display MDN links to a locale that is not the user's preferred locale (even if the browser indicates this locale as a preferred language).
  2. We show fallback links to en-US if a page is not available in a locale, but this means the user has to manually navigate back to their preferred locale.

Solution

We already have a preferredlocale cookie that we set when the user switches the locale in the user interface.

Use this cookie to automatically redirect the user to the preferred locale under these circumstances:

  1. The user has set a preferred locale.
  2. The requested page is NOT in the preferred locale.
  3. The requested page is available in the preferred locale.

Caveat: Changing the locale directly in the address bar will still redirect back.


How did you test this change?

Ran npm start in /cloud-function, then tested locally with xh:

% xh -h localhost:5100/en-US/docs/Web
HTTP/1.1 200 OK

% xh -h localhost:5100/fr/docs/Web   
HTTP/1.1 200 OK

% xh -h localhost:5100/fr/docs/Web cookie:preferredlocale=en-US
HTTP/1.1 302 Found
Cache-Control: no-store
Location: /en-US/docs/Web

% xh -h localhost:5100/en-US/docs/Web cookie:preferredlocale=fr
HTTP/1.1 302 Found
Cache-Control: no-store
Location: /fr/docs/Web

@caugner caugner requested a review from a team as a code owner July 23, 2024 10:20
@caugner caugner changed the title Mp 1242 redirect to preferred locale feat(cloud-function): always redirect to preferred locale Jul 23, 2024
@github-actions github-actions bot added redirects all things related to redirecting cloud-function labels Jul 23, 2024
Copy link
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

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

Code looks good, but I'm torn on the overall behaviour:

Obviously the current behaviour is an annoyance to many users, since we've received a number of reports about it, but a fix which results in pasting a link containing e.g. the fr locale in and being redirected to en-US because of prior behaviour feels wrong.

However, I don't see an elegant way to do this in some cases but not others, so this feels like the best approach for most people. Let's see if we get an influx of issues filed saying they want something like the old behaviour back.

I imagine most users who need to switch between locales a lot are in our close community (eng/content/l10n), and perhaps we should let them know ahead of time that setting the cookie to something like false will disable this behaviour - perhaps we should explicitly support that, and leave it untouched when using the dropdown menu in this case - that can be a follow up task/PR though.

@caugner
Copy link
Contributor Author

caugner commented Jul 25, 2024

pasting a link containing e.g. the fr locale in and being redirected to en-US because of prior behaviour feels wrong

I realize that this could indeed be an annoyance for us, when looking at issues, and for translators.

perhaps we should let them know ahead of time that setting the cookie to something like false will disable this behaviour - perhaps we should explicitly support that

I agree that we should support opt-out from this feature, maybe even via the UI from the locale dropdown.

@DonalMe
Copy link

DonalMe commented Aug 30, 2024

fwiw I filled #11717
It might be duplicated in this ongoing effort but just in case

@caugner caugner changed the title feat(cloud-function): always redirect to preferred locale feat(language-menu): add automatic redirect experiment Sep 12, 2024
@caugner caugner force-pushed the MP-1242-redirect-to-preferred-locale branch from d539049 to a3be882 Compare September 12, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloud-function metrics redirects all things related to redirecting
Projects
None yet
3 participants