aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/generateJsonI18n.php
diff options
context:
space:
mode:
authorAdam Roses Wight <awight@wikimedia.org>2014-04-01 02:07:37 -0700
committerReedy <reedy@wikimedia.org>2014-05-10 15:40:27 +0100
commit0b655e4810ed3b1efbf5220f892417144bbecd2b (patch)
treeb6b7405659bdde59a7fbe676d2701fefbe11e8ca /maintenance/generateJsonI18n.php
parent68bdc4f7f4eb1109e27fad33676010276853d58f (diff)
downloadmediawikicore-0b655e4810ed3b1efbf5220f892417144bbecd2b.tar.gz
mediawikicore-0b655e4810ed3b1efbf5220f892417144bbecd2b.zip
Add --supplementary flag to generateJsonI18n
Recursively searches the DonationInterface extension for i18n files and performs default conversion on the lot. Usage: php maintenance/generateJsonI18n.php \ --extension DonationInterface --supplementary Change-Id: I8e61c3d0f34394c0d766cf9532df9ac221ce7405
Diffstat (limited to 'maintenance/generateJsonI18n.php')
-rw-r--r--maintenance/generateJsonI18n.php26
1 files changed, 25 insertions, 1 deletions
diff --git a/maintenance/generateJsonI18n.php b/maintenance/generateJsonI18n.php
index 81d8381c1823..83e731ab9f3a 100644
--- a/maintenance/generateJsonI18n.php
+++ b/maintenance/generateJsonI18n.php
@@ -44,6 +44,8 @@ class GenerateJsonI18n extends Maintenance {
$this->addOption( 'extension', 'Perform default conversion on an extension',
false, true );
$this->addOption( 'shim-only', 'Only create or update the backward-compatibility shim' );
+ $this->addOption( 'supplementary', 'Find supplementary i18n files in subdirs and convert those',
+ false, false );
}
public function execute() {
@@ -52,6 +54,7 @@ class GenerateJsonI18n extends Maintenance {
$phpfile = $this->getArg( 0 );
$jsondir = $this->getArg( 1 );
$extension = $this->getOption( 'extension' );
+ $convertSupplementaryI18nFiles = $this->hasOption( 'supplementary' );
if ( $extension ) {
if ( $phpfile ) {
@@ -66,7 +69,28 @@ class GenerateJsonI18n extends Maintenance {
// dies.
}
- $this->transformI18nFile( $phpfile, $jsondir );
+ if ( $convertSupplementaryI18nFiles ) {
+ if ( is_readable( $phpfile ) ) {
+ $this->transformI18nFile( $phpfile, $jsondir );
+ } else {
+ // This is non-fatal because we might want to continue searching for
+ // i18n files in subdirs even if the extension does not include a
+ // primary i18n.php.
+ $this->error( "Warning: no primary i18n file was found." );
+ }
+ $this->output( "Searching for supplementary i18n files...\n" );
+ $dir_iterator = new RecursiveDirectoryIterator( dirname( $phpfile ) );
+ $iterator = new RecursiveIteratorIterator( $dir_iterator, RecursiveIteratorIterator::LEAVES_ONLY );
+ foreach ( $iterator as $path => $fileObject ) {
+ if ( fnmatch( "*.i18n.php", $fileObject->getFilename() ) ) {
+ $this->output( "Converting $path.\n" );
+ $this->transformI18nFile( $path );
+ }
+ }
+ } else {
+ // Just convert the primary i18n file.
+ $this->transformI18nFile( $phpfile, $jsondir );
+ }
}
public function transformI18nFile( $phpfile, $jsondir = null ) {