As a Wikidata editor, I want to see labels in languages that are relevant to me, according to my Babel information.
**Problem:**
I noticed this while working on T297393: `LanguageFallbackChainFactory::buildFromBabel()` first adds the babel languages, then their variants, and then for each language all of the fallbacks. This means that the implicit fallback to `en` is added after all the explicit fallbacks of the first Babel language, but before the explicit fallbacks of any other Babel languages.
**Example:**
Consider a user with the following Babel. **arz-5, frc-4**. (`arz` Egyptian Arabic falls back to `ar` Arabic; `frc` Cajun French falls back to `fr` French.)
I posit that they should get the following language fallback chain: arz, frc, ar, fr, en.
However, they currently get the following fallback chain: arz, frc, ar, //en, fr//.
**Aside: on Variants**
In the description and example above, I’ve left out language variants, which also factor into the chain. For languages that have variants (e.g. `zh`: `zh`, `zh-hans`, `zh-hant`, …), those variants are inserted into the fallback chain immediately after the main language, and //before// the next Babel language. For example, the babel zh-5, de-4 would produce a chain like zh, zh-hans, zh-hant, … de, en. In a way, language variants are prioritized above language fallbacks: Babel order trumps language fallback order, but variants trump the Babel order. This task doesn’t propose any changes to the handling of language variants.
**Screenshots/mockups:**
```lang=php,name=maintenance/shell.php
>>> array_map( function ( $lwc ) { return $lwc->getLanguageCode(); }, \Wikibase\Repo\WikibaseRepo::getLanguageFallbackChainFactory()->buildFromBabel( [ '5' => [ 'arz' ], '4' => [ 'frc' ] ] ) )
=> [
"arz",
"frc",
"ar",
"en",
"fr",
]
```
**BDD****Pseudocode:**
GIVEN
AND
WHEN
AND
THEN
AND
**Acceptance criteria:**
* The Babel fallback chain lists the explicit language fallbacks of all Babel languages before any implicit fallbacks (`en` and, with T297393, `mul`) – unless the implicit fallbacks are also explicit fallbacks, of course (e.g. if the Babel includes `sco` Scots, which explicitly falls back to `en`).
**Open questions:**
---
Pseudocode of the current version:
- for each Babel language:
- add language
- add language’s variants (if any)
- for each Babel language:
- add language’s fallbacks and their variants
Pseudocode of the proposed change:
- for each Babel language:
- add language
- add language’s variants (if any)
- for each Babel language:
- add language’s **explicit fallbacks** and their variantsts
- add **implicit fallbacks** (en, mul)
**Acceptance criteria:**
- add implicit fallbacks (en* The Babel fallback chain lists the explicit language fallbacks of all Babel languages before any implicit fallbacks (`en` and, with T297393, `mul`) – unless the implicit fallbacks are also explicit fallbacks, of course (e.g. if the Babel includes `sco` Scots, mul)which explicitly falls back to `en`).