Context:
Some wikis need the ability to localize page output to the user's preferred language. A good example would be Wikimedia Commons, which uses the Translate extension to localize help and policy pages, and the {{int:...}} parser function to localize file description pages. These mechanism also cause the parser cache to be split by user language.
Currently, core lacks a mechanism that would allow extensions to know in what language a page is currently being rendered. Parser::getTargetLanguage and ParserOptions::getTargetLanguage currently return the wiki's content lanuage in nearly all cases, and give no indication of whether the content is actually being localiezd or not, and has by itself no impact on whether the parser cache gets split.
Proposal:
* It should be possible for a wiki to specify that pages should be show in the user language (could be done globally for all pages, or by namespace, or triggered by a magic word on the page). When rendering a page that is multilingual, ParserOptions::getTargetLanguage is set to the user language.
* The parser cache, the {{int:...}} function, and other functionality that may depend on the user language, like formatting code for wikidata statements, would rely on ParserOptions::getTargetLanguage to tell them what language to use.
* Parser::getTargetLanguage should return ParserOptions::getTargetLanguage unchanged, the logic currently in Parser::getTargetLanguage should be migrated to whatever code sets the target language in the options.
* Possibly drop Title::getDisplayLanguage and ContentHandler::getDisplayLanguage completely, or move the functionality elsewhere (maybe into the Language object).
See also:
* {T109705}