$desc = $this->descriptor;
if ( is_string( $desc ) ) {
return $this->basePath . '/' . $desc;
- } elseif ( isset( $desc['lang'][$context->getLanguage()] ) ) {
- return $this->basePath . '/' . $desc['lang'][$context->getLanguage()];
- } elseif ( isset( $desc[$context->getDirection()] ) ) {
+ }
+ if ( isset( $desc['lang'] ) ) {
+ $contextLang = $context->getLanguage();
+ if ( isset( $desc['lang'][$contextLang] ) ) {
+ return $this->basePath . '/' . $desc['lang'][$contextLang];
+ }
+ $fallbacks = Language::getFallbacksFor( $contextLang );
+ foreach ( $fallbacks as $lang ) {
+ // Images will fallback to 'default' instead of 'en', except for 'en-*' variants
+ if (
+ ( $lang !== 'en' || substr( $contextLang, 0, 3 ) === 'en-' ) &&
+ isset( $desc['lang'][$lang] )
+ ) {
+ return $this->basePath . '/' . $desc['lang'][$lang];
+ }
+ }
+ }
+ if ( isset( $desc[$context->getDirection()] ) ) {
return $this->basePath . '/' . $desc[$context->getDirection()];
- } else {
- return $this->basePath . '/' . $desc['default'];
}
+ return $this->basePath . '/' . $desc['default'];
}
/**
[ 'mno', 'ar', 'mno-rtl.svg' ],
[ 'mno', 'he', 'mno-ltr.svg' ],
[ 'pqr', 'en', 'pqr-b.svg' ],
+ [ 'pqr', 'en-gb', 'pqr-b.svg' ],
[ 'pqr', 'de', 'pqr-f.svg' ],
+ [ 'pqr', 'de-formal', 'pqr-f.svg' ],
[ 'pqr', 'ar', 'pqr-f.svg' ],
[ 'pqr', 'fr', 'pqr-a.svg' ],
[ 'pqr', 'he', 'pqr-a.svg' ],
public function testGetPath( $imageName, $languageCode, $path ) {
static $dirMap = [
'en' => 'ltr',
+ 'en-gb' => 'ltr',
'de' => 'ltr',
+ 'de-formal' => 'ltr',
'fr' => 'ltr',
'he' => 'rtl',
'ar' => 'rtl',