23use InvalidArgumentException;
44 private $siteLangCode;
47 private $localisationCache;
50 private $langNameUtils;
53 private $fallbackCache = [];
68 $this->siteLangCode = $siteLangCode;
69 $this->localisationCache = $localisationCache;
70 $this->langNameUtils = $langNameUtils;
81 return $this->
getAll( $code )[0] ??
null;
94 public function getAll( $code, $mode = self::MESSAGES ) {
98 if ( $code ===
'en' || !$this->langNameUtils->isValidBuiltInCode( $code ) ) {
105 $ret = $this->localisationCache->getItem( $code,
'fallbackSequence' ) ?: [
'en' ];
112 $ret = $this->localisationCache->getItem( $code,
'originalFallbackSequence' );
116 throw new InvalidArgumentException(
"Invalid fallback mode \"$mode\"" );
132 $cacheKey =
"{$code}-{$this->siteLangCode}";
134 if ( !array_key_exists( $cacheKey, $this->fallbackCache ) ) {
135 $fallbacks = $this->
getAll( $code );
137 if ( $code === $this->siteLangCode ) {
139 $siteFallbacks = [ $code ];
142 $siteFallbacks = $this->
getAll( $this->siteLangCode );
143 array_unshift( $siteFallbacks, $this->siteLangCode );
146 $siteFallbacks = array_diff( $siteFallbacks, $fallbacks );
149 $this->fallbackCache[$cacheKey] = [ $fallbacks, $siteFallbacks ];
151 return $this->fallbackCache[$cacheKey];
Caching for the contents of localisation files.