MediaWiki  1.34.0
LocalisationUpdate.php
Go to the documentation of this file.
1 <?php
2 
13  public static function onRecacheFallback( LocalisationCache $lc, $code, array &$cache ) {
14  $dir = self::getDirectory();
15  if ( !$dir ) {
16  return;
17  }
18 
19  $fileName = "$dir/" . self::getFilename( $code );
20  if ( is_readable( $fileName ) ) {
21  $data = FormatJson::decode( file_get_contents( $fileName ), true );
22  $cache['messages'] = array_merge( $cache['messages'], $data );
23  }
24  }
25 
32  public static function onRecache( LocalisationCache $lc, $code, array &$cache ) {
33  $dir = self::getDirectory();
34  if ( !$dir ) {
35  return;
36  }
37 
38  $codeSequence = array_merge( [ $code ], $cache['fallbackSequence'] );
39  foreach ( $codeSequence as $csCode ) {
40  $fileName = "$dir/" . self::getFilename( $csCode );
41  $cache['deps'][] = new FileDependency( $fileName );
42  }
43  }
44 
51  public static function getDirectory() {
52  global $wgLocalisationUpdateDirectory, $wgCacheDirectory;
53 
54  return $wgLocalisationUpdateDirectory ?: $wgCacheDirectory;
55  }
56 
64  public static function getFilename( $language ) {
65  return "l10nupdate-$language.json";
66  }
67 }
FileDependency
Definition: FileDependency.php:27
LocalisationUpdate\onRecache
static onRecache(LocalisationCache $lc, $code, array &$cache)
Hook: LocalisationCacheRecache.
Definition: LocalisationUpdate.php:32
LocalisationUpdate\onRecacheFallback
static onRecacheFallback(LocalisationCache $lc, $code, array &$cache)
Hook: LocalisationCacheRecacheFallback.
Definition: LocalisationUpdate.php:13
$wgCacheDirectory
$wgCacheDirectory
Directory for caching data in the local filesystem.
Definition: DefaultSettings.php:2326
FormatJson\decode
static decode( $value, $assoc=false)
Decodes a JSON string.
Definition: FormatJson.php:174
LocalisationUpdate\getFilename
static getFilename( $language)
Returns a filename where updated translations are stored.
Definition: LocalisationUpdate.php:64
LocalisationUpdate
Definition: Fetcher.php:8
LocalisationCache
Class for caching the contents of localisation files, Messages*.php and *.i18n.php.
Definition: LocalisationCache.php:41
LocalisationUpdate\getDirectory
static getDirectory()
Returns a directory where updated translations are stored.
Definition: LocalisationUpdate.php:51
$cache
$cache
Definition: mcc.php:33