Adamw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/122659

Change subject: Adds an --extension option to generateJsonI18n
......................................................................

Adds an --extension option to generateJsonI18n

Usage:
        php maintenance/generateJsonI18n.php --extension WikiLove
Performs the default conversions in $IP/extensions/WikiLove/, replacing
the WikiLove.i18n.php file with a backwards-compatibility shim and porting
messages to the WikiLove/i18n/ directory.

This patch has the side-effect of making the second cmdline argument in
the ordinary usage optional.  When omitted, we will make the default guess
as to $jsondir, that it should live in the same directory as the .i18n.php file.

Change-Id: I6246d2c4eb7327d6dcc503421b71ffdcaf01769c
---
M maintenance/generateJsonI18n.php
1 file changed, 33 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/59/122659/1

diff --git a/maintenance/generateJsonI18n.php b/maintenance/generateJsonI18n.php
index 27a9ff1..13d1336 100644
--- a/maintenance/generateJsonI18n.php
+++ b/maintenance/generateJsonI18n.php
@@ -36,15 +36,46 @@
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Build JSON messages files from a PHP 
messages file";
-               $this->addArg( 'phpfile', 'PHP file defining a $messages 
array', true );
-               $this->addArg( 'jsondir', 'Directory to write JSON files to', 
true );
+               $this->addArg( 'phpfile', 'PHP file defining a $messages 
array', false );
+               $this->addArg( 'jsondir', 'Directory to write JSON files to', 
false );
                $this->addOption( 'langcode', 'Language code; only needed for 
converting core i18n files',
+                       false, true );
+               $this->addOption( 'extension', 'Perform default conversion on 
an extension',
                        false, true );
        }
 
        public function execute() {
+               global $IP;
+
                $phpfile = $this->getArg( 0 );
                $jsondir = $this->getArg( 1 );
+               $extension = $this->getOption( 'extension' );
+               $hasAdditionalI18nFiles = $this->getOption( 'supplements' );
+
+               if ( $extension and !$phpfile ) {
+                       $phpfile = 
"$IP/extensions/$extension/$extension.i18n.php";
+               }
+
+               if ( !$phpfile ) {
+                       $this->error( "I'm here for an argument!" );
+                       $this->maybeHelp( true );
+                       // dies.
+               }
+
+               $this->transformI18nFile( $phpfile, $jsondir );
+       }
+
+       public function transformI18nFile( $phpfile, $jsondir = null ) {
+               $phpfile = realpath( $phpfile );
+               if ( !$jsondir ) {
+                       // Assume the json directory should be in the same 
directory as the
+                       // .i18n.php file.
+                       $jsondir = dirname( $phpfile ) . "/i18n";
+               }
+               if ( !is_dir( $jsondir ) ) {
+                       $this->output( "Creating directory $jsondir.\n" );
+                       mkdir( $jsondir );
+               }
 
                if ( !is_readable( $phpfile ) ) {
                        $this->error( "Error reading $phpfile\n", 1 );

-- 
To view, visit https://gerrit.wikimedia.org/r/122659
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6246d2c4eb7327d6dcc503421b71ffdcaf01769c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to