operations icon indicating copy to clipboard operation
operations copied to clipboard

Enable `{{USERLANGUAGE}}` magic word on wiki

Open 1ec5 opened this issue 5 months ago • 0 comments

The OSM Wiki’s chef configuration should set $wgParserEnableUserLanguage to enable the {{USERLANGUAGE}} magic word in templates.

Rationale

Some pages should contain multilingual content. For example, a file can have only a single description page, but users should see the description in their own language. Similarly, many templates are used by speakers of every language, but currently only the English documentation is on the template’s own page; other languages get shunted onto other pages. MediaWiki allows us to set the page’s content language using Special:PageLanguage and access it using {{PAGELANGUAGE}}, but a page can only have one content language at a time.

Historically, Wikimedia’s multilingual wikis, such as Commons, resorted to the hack of setting MediaWiki:Lang, MediaWiki:Lang/ar, etc. to an ISO language code and writing {{#switch: {{int:lang}} | … }} in templates. This forces MediaWiki to evaluate the page differently depending on the user language. We’ve have multiple requests to implement something similar on our wiki, but it’s very tedious and I’m not sure if it’s a good idea from a performance perspective. (The conventional wisdom is that more MediaWiki: messages = slower performance sitewide.)

MediaWiki 1.43 and above supports a {{USERLANGUAGE}} magic word that resolves to the ISO language code of the localization that the user has selected. Unfortunately, by default, this magic word always resolves to the page content language. $wgParserEnableUserLanguage allows it to resolve to the user’s actual language. The default behavior is probably because the cache can’t necessarily serve the same content to users of two different languages, but the magic word is intended to make the caching behavior more predictable than implicitly relying on the value of a custom interface message.

1ec5 avatar Aug 03 '25 01:08 1ec5