]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - extensions/LocalisationUpdate/LocalisationUpdate.class.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / extensions / LocalisationUpdate / LocalisationUpdate.class.php
1 <?php
2
3 /**
4  * Class for localization update hooks and static methods.
5  */
6 class LocalisationUpdate {
7         /**
8          * Hook: LocalisationCacheRecacheFallback
9          */
10         public static function onRecacheFallback( LocalisationCache $lc, $code, array &$cache ) {
11                 $dir = self::getDirectory();
12                 if ( !$dir ) {
13                         return true;
14                 }
15
16                 $fileName = "$dir/" . self::getFilename( $code );
17                 if ( is_readable( $fileName ) ) {
18                         $data = FormatJson::decode( file_get_contents( $fileName ), true );
19                         $cache['messages'] = array_merge( $cache['messages'], $data );
20                 }
21
22                 return true;
23         }
24
25         /**
26          * Hook: LocalisationCacheRecache
27          */
28         public static function onRecache( LocalisationCache $lc, $code, array &$cache ) {
29                 $dir = self::getDirectory();
30                 if ( !$dir ) {
31                         return true;
32                 }
33
34                 $codeSequence = array_merge( [ $code ], $cache['fallbackSequence'] );
35                 foreach ( $codeSequence as $csCode ) {
36                         $fileName = "$dir/" . self::getFilename( $csCode );
37                         $cache['deps'][] = new FileDependency( $fileName );
38                 }
39
40                 return true;
41         }
42
43         /**
44          * Returns a directory where updated translations are stored.
45          *
46          * @return string|false False if not configured.
47          * @since 1.1
48          */
49         public static function getDirectory() {
50                 global $wgLocalisationUpdateDirectory, $wgCacheDirectory;
51
52                 return $wgLocalisationUpdateDirectory ?: $wgCacheDirectory;
53         }
54
55         /**
56          * Returns a filename where updated translations are stored.
57          *
58          * @param string $language Language tag
59          * @return string
60          * @since 1.1
61          */
62         public static function getFilename( $language ) {
63                 return "l10nupdate-$language.json";
64         }
65 }