mdn / yari

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

Suggest fallback in current locale if en-US version redirects to a page that is available in that locale #2528

Open peterbe opened 3 years ago

peterbe commented 3 years ago

See https://developer.mozilla.org/fr/docs/web/guide/css/getting_started/why_use_css This says 404, which might be perfectly true, but if you manually edit the URL to /en-US/ it actually does work.

peterbe commented 3 years ago

@fiji-flo As you can see, https://developer.mozilla.org/en-us/docs/web/guide/css/getting_started/why_use_css is a 301 but https://developer.mozilla.org/en-us/docs/web/guide/css/getting_started/why_use_css/index.json isn't.

I think the 301 comes from a fundamental redirect, but that lookup doesn't work when you append /index.json. Can you think of a neat and simple way to do the fundamental redirect lookup "with and without" the /index.json suffix?

peterbe commented 3 years ago

@fiji-flo https://github.com/mdn/yari/issues/2713 is a great example too to test this.

peterbe commented 3 years ago

@fiji-flo Is there any point in doing this? ...soon. ...after we've done the translated-content slug sync.

See https://github.com/mdn/yari/issues/2713 I don't know how a user got to https://developer.mozilla.org/es/docs/Web/Events/statechange, perhaps it was an old bookmark, but once es gets all the redirects that en-US has, it'll get taken care of automatically. Because translated-content has, in files/en-us/_redirects this line:

/en-US/docs/Web/Events/statechange      /en-US/docs/Web/API/RTCIceTransport/statechange_event

So if you run yarn tool sync-translated-content es won't that create an entry in translated-content/files/es/_redirects that is exactly like that but es. I.e.

/es/docs/Web/Events/statechange      /es/docs/Web/API/RTCIceTransport/statechange_event
peterbe commented 3 years ago

Actually, I looked at the translated-content repo. https://github.com/mdn/translated-content/blob/main/files/es/_redirects.txt does not have the same redirects as en-us has. Is that because of a bug? or perhaps you haven't run the sync for es recently. Because, shouldn't es have its own redirects (e.g. Spanish translated slugs) and those from en-us?

fiji-flo commented 3 years ago

yarn tool sync-translated-content es shouldn't create that as https://developer.mozilla.org/es/docs/Web/API/RTCIceTransport/statechange_event does not (and will not) exist.

Overall I'm still voting for dropping react routing and not having any index.json but we can also work on fixing redirects for them.

peterbe commented 3 years ago

yarn tool sync-translated-content es shouldn't create that as https://developer.mozilla.org/es/docs/Web/API/RTCIceTransport/statechange_event does not (and will not) exist.

Ok. Gotcha. Yeah, it's a moot example because the final destination URL wouldn't end up in a 200 for Spanish.

My brains still hurting from trying to pretend to keep up with you. There's so much going on that it's confusing.

Let's switch the example from es to fr instead. The gist of my high-level case is that we used to have:

-/fr/docs/Old_french_slug ==> /fr/docs/New_french_slug
+/fr/docs/New_french_slug ==> /fr/docs/New_english_slug
+/fr/docs/Old_french_slug ==> /fr/docs/New_english_slug

...assuming there exists a (after the unslug) file called files/fr/new_english_slug/index.html.

fiji-flo commented 3 years ago

And that should be the case, yes!

peterbe commented 3 years ago

https://github.com/mdn/yari/pull/3254 is going to avoid even getting to the 404 page because a lot of translated document's hyperlinks are now automatically switched over to the en-US equivalent and it does this using redirects.

caugner commented 1 year ago

tl;dr When I visit https://developer.mozilla.org/fr/docs/web/guide/css/getting_started/why_use_css, I see:

image

If I click on that link, I get to https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps/How_CSS_works.

And that page is actually available in French: https://developer.mozilla.org/fr/docs/Learn/CSS/First_steps/How_CSS_works

So when we find a fallback, and that slug differs from the currently visited page, we should check if it might exist in the same locale, and redirect there.