Improve OutputPage::showErrorPage method documentation
[lhc/web/wiklou.git] / maintenance / generateJsonI18n.php
index f3f8943..9c8354c 100644 (file)
@@ -90,7 +90,44 @@ class GenerateJsonI18n extends Maintenance {
                        }
                        $this->output( "$jsonfile\n" );
                }
+
+               if ( !$this->hasOption( 'langcode' ) ) {
+                       $shim = $this->doShim( $jsondir );
+                       file_put_contents( $phpfile, $shim );
+               }
+
                $this->output( "All done.\n" );
+               $this->output( "Also add \$wgMessagesDirs['YourExtension'] = __DIR__ . '/i18n';\n" );
+       }
+
+       protected function doShim( $jsondir ) {
+               $shim = <<<'PHP'
+<?php
+$messages = array();
+$GLOBALS['wgHooks']['LocalisationCacheRecache'][] = function ( $cache, $code, &$cachedData ) {
+       $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] );
+       foreach ( $codeSequence as $csCode ) {
+               $fileName = __DIR__ . "/{{OUT}}/$csCode.json";
+               if ( is_readable( $fileName ) ) {
+                       $data = FormatJson::decode( file_get_contents( $fileName ), true );
+                       foreach ( array_keys( $data ) as $key ) {
+                               if ( $key === '' || $key[0] === '@' ) {
+                                       unset( $data[$key] );
+                               }
+                       }
+                       $cachedData['messages'] = array_merge( $data, $cachedData['messages'] );
+               }
+
+               $cachedData['deps'][] = new FileDependency( $fileName );
+       }
+       return true;
+};
+
+PHP;
+
+               $jsondir = str_replace('\\', '/', $jsondir );
+               $shim = str_replace( '{{OUT}}', $jsondir, $shim );
+               return $shim;
        }
 
        /**