Localized URLs Hardcoded

Hello,

I’ve seen a few pages on MDN that use localized hardcoded URLs in another language, such as German.

For example: When viewing an MDN page in English, a link on the page might point to /de/docs/Glossary/Sloppy_mode, which is the German version of the page I should be pointed to in English.

My question is: If I were to clean up the URLs on MDN pages what is the best way to link to internal MDN pages? Should any language localization be removed from the URLs?

Thank you,
James

1 Like

Hi James! Thanks for contributing to MDN!

Good question! The best practice would be to remove the locale string from the URL (that is, start the relative URL with “/docs”). When a user follows such a link, MDN resolves the locale to the user’s browser preference. For example, if their browser locale is Spanish, they get “/es/docs/…”. If that page doesn’t exist in their preferred language, then they see the English page with a banner at the top (that hopefully has been translated), telling them that the page has not been translated in their language, and inviting them to contribute a translation.

As I said, that would be a best practice, but we haven’t actually been doing it consistently. For example, the link picker UI in the editor includes the locale in the URL. One consequence of this is that there are a lot of “/en-US” links hardcoded in translated pages, because localizers translate the text, but don’t always change the links. I’m not sure how we would end up with “/de” links in English pages, but it might happen by someone selecting a URL with the wrong locale by mistake.

In short, to answer your question, yes, removing locale strings from internal links would be the ideal way to clean up URLs. But it would also be a very big job to fix all the links that include locale strings, because there are so many of them. Definitely remove them from links where the locale string is incorrect for the language of the page where they appear.

–Janet

1 Like

You should include the locale in the URL in nearly all if not all cases. This avoids a redirect that would slow down page loads for users.

Sheppy

1 Like

I agree with @sheppy here and basically, English pages should have /en-US/links and there shouldn’t be any /de/links on English pages.

The rest applies especially when localizing.
Basically there are two ways to “build” internal links:

  • the “quick&dirty” way (1 guaranteed redirect): /<myLocale>/rest/of/the/english/URL (eg. /de/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse): if the page exists in German, it will redirect to it and if not, it will redirect to the English page with a “call to action” box at the top

  • the “longer/proper” way: type the target URL in your browser by changing the locale code :

    • if the page is localized: take the URL fragment to copy it in the editor
    • if the page isn’t localized: use /<myLocale>/rest/of/the/english/URL (aka basically changing /en-US/ by your local code)
1 Like

About the only time I advocate using URLs without the locale included is when linking to MDN content from outside MDN. This way, your link works regardless of the user’s locale and is more likely to reach the page they really want.

Sheppy

2 Likes

A good ol’ “yaaasssss” to this :slight_smile:

After many user interviews I agree that it would be better to hardcode the locale. A lot of people choose the English version of an MDN page deliberately. With a non-locale link the next page would open in their own locale again (assuming accept language is not English). It’s mitigated somewhat with the recent fix that allows people to set their default locale, but it’s still incovenient.

1 Like