4 * Class for localization update hooks and static methods.
6 class LocalisationUpdate {
8 * Hook: LocalisationCacheRecacheFallback
10 public static function onRecacheFallback( LocalisationCache $lc, $code, array &$cache ) {
11 $dir = self::getDirectory();
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 );
26 * Hook: LocalisationCacheRecache
28 public static function onRecache( LocalisationCache $lc, $code, array &$cache ) {
29 $dir = self::getDirectory();
34 $codeSequence = array_merge( [ $code ], $cache['fallbackSequence'] );
35 foreach ( $codeSequence as $csCode ) {
36 $fileName = "$dir/" . self::getFilename( $csCode );
37 $cache['deps'][] = new FileDependency( $fileName );
44 * Returns a directory where updated translations are stored.
46 * @return string|false False if not configured.
49 public static function getDirectory() {
50 global $wgLocalisationUpdateDirectory, $wgCacheDirectory;
52 return $wgLocalisationUpdateDirectory ?: $wgCacheDirectory;
56 * Returns a filename where updated translations are stored.
58 * @param string $language Language tag
62 public static function getFilename( $language ) {
63 return "l10nupdate-$language.json";