Background: In researching T250930: Wikibase receiving ⧼Lang⧽ from uselang parameter and using it everwhere (related: T247057) it became clear that our handling of languages is suboptimal. One far-reaching way to tackle that would be to introduce a TermLanguage class (and TermLanguageFactory) that guarantees to be a valid Term language. However, that would be a very fundamental change of a magnitude that would require an ADR. Further, it seems that most of our problems in that regard seem to stem from "invalid" languages that are provided by our own \Wikibase\Lib\LanguageFallbackChain, created by our \Wikibase\Lib\LanguageFallbackChainFactory.
So it might be possible to improve this situation by taking the following actions:
- \Wikibase\Lib\LanguageFallbackChain and \Wikibase\Lib\LanguageFallbackChainFactory should be renamed TermLanguageFallbackChain and TermLanguageFallbackChainFactory reduce confusion with MediaWiki's LanguageFallbackChain for interface messages.
- The factory should contain validation to ensure that the languages are only valid Term languages.
However, that is based on the following assumptions:
\Wikibase\Lib\LanguageFallbackChain is only used for Terms
It is necessary to investigate whether that assumption is correct and whether the actions above can be taken.
One place, where these fallback chains seem to be used a lot, at least intermittently, is in the \ValueFormatters\FormatterOptions. There is an extra investigation to look into how that class is used and maybe can be improved upon: T256407: Investigate where and with which keys FormatterOptions are used
(Looking into JS Term languages is not part of this investigation)