mdn / yari

The platform code behind MDN Web Docs
Mozilla Public License 2.0
1.19k stars 508 forks source link

URLs without locales do not do correct locale fallback #11717

Open DonalMe opened 2 months ago

DonalMe commented 2 months ago

Summary

We do not include a local in the MDN URLs in the Firefox release notes. The goal is for users in non-en locales following links in the release notes to be correctly redirected to their locale. This is not working for MDN URLs and leads to a 404 in non-English locales.

URL

Example: https://developer.mozilla.org/docs/Web/API/WebCodecs_API

Reproduction steps

  1. Browse in a non-en locale
  2. Navigate to a MDN URL without a locale (example https://developer.mozilla.org/docs/Web/API/WebCodecs_API)

Expected behavior

There should be a redirect to your locale (example https://developer.mozilla.org/fr/docs/Web/API/WebCodecs_API)

Actual behavior

404 page

Device

Desktop

Browser

Firefox

Browser version

Stable

Operating system

Mac OS

Screenshot

No response

Anything else?

curl --header "Accept-Language: fr,fr-fr,en-us,en" -LIs https://developer.mozilla.org/docs/Web/API/WebCodecs_API | grep HTTP

Validations

caugner commented 2 months ago

@DonalMe Overall, this seems to work as intended: https://developer.mozilla.org/docs/Web/API/WebCodecs_API redirects to https://developer.mozilla.org/fr/docs/Web/API/WebCodecs_API, because this is the first locale in the Accept-Language header that MDN supports, but since the page isn't localized yet, a 404 page is displayed instead, with a link to the English version.

Do you expect to be redirected to en-US instead, because it's the first locale listed in the Accept-Language header for which the page exists?

DonalMe commented 2 months ago

@caugner sorry, I didn't realize this behavior was because the page wasn't localized. If the redirect works when the page is localized, maybe it should fallback to en-us when it is not localized instead of a 404?

pascalchevrel commented 2 months ago

IMO, MDN should go through all the accept-lang fallback locales through content negociation (https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation#the_accept-language_header)

caugner commented 1 month ago

Thank you for this suggestion, it does make sense to me do content negociation, rather than redirecting to the first locale in the list of accepted languages that we support. We will discuss this in the team, and prioritize accordingly.

Note that https://github.com/mdn/yari/pull/11518 will not fix this.

caugner commented 3 weeks ago

FWIW The link is here.

Enabled the Web Codecs API on desktop platforms, allowing low-level access to audio and video encoders and decoders.

(Meanwhile, the en-US locale seems to have been added to the link, given that it is not available in most locales.)