r73890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73889‎ | r73890 | r73891 >
Date:14:27, 28 September 2010
Author:siebrand
Status:deferred
Tags:
Comment:
All exporting multiple non-meta message groups using --groups or --grouptrail.
Modified paths:
  • /trunk/extensions/Translate/scripts/export.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/export.php
@@ -9,7 +9,7 @@
1010 * @file
1111 */
1212
13 -$optionsWithArgs = array( 'lang', 'skip', 'target', 'group', 'threshold', 'ppgettext' );
 13+$optionsWithArgs = array( 'lang', 'skip', 'target', 'group', 'groups', 'grouptrail', 'threshold', 'ppgettext' );
1414 require( dirname( __FILE__ ) . '/cli.inc' );
1515
1616 function showUsage() {
@@ -22,7 +22,10 @@
2323 --target Target directory for exported files
2424 --lang Comma separated list of language codes or *
2525 --skip Languages to skip, comma separated list
26 - --group Group ID
 26+ --group Group ID (cannot use groups grouptrial)
 27+ --groups Group IDs, comma separated list (cannot use group or grouptrial)
 28+ --grouptrail Trial for IDs of to be exported message groups (cannot use
 29+ group or grouptrial)
2730 --threshold Do not export under this percentage translated
2831 --ppgettext Group root path for checkout of product. "msgmerge" will post
2932 process on the export result based on the current definitionFile
@@ -52,8 +55,8 @@
5356 $skip = array();
5457 }
5558
56 -if ( !isset( $options['group'] ) ) {
57 - STDERR( "You need to specify group" );
 59+if ( !isset( $options['group'] ) && !isset( $options['groups'] ) && !isset( $options['grouptrail'] ) ) {
 60+ STDERR( "You need to specify one or more groups using any of the options 'group', 'groups' or 'grouptrail'" );
5861 exit( 1 );
5962 }
6063
@@ -61,6 +64,7 @@
6265 STDERR( "Target directory is not writable (" . $options['target'] . ")" );
6366 exit( 1 );
6467 }
 68+
6569 if ( isset( $options['threshold'] ) && intval( $options['threshold'] ) ) {
6670 $threshold = $options['threshold'];
6771 } else {
@@ -69,66 +73,92 @@
7074
7175 $langs = Cli::parseLanguageCodes( $options['lang'] );
7276
73 -$group = MessageGroups::getGroup( $options['group'] );
 77+$groups = array();
7478
75 -if ( !$group instanceof MessageGroup ) {
76 - STDERR( "Invalid group: " . $options['group'] );
77 - exit( 1 );
78 -}
 79+if( isset( $options['group'] ) ) {
 80+ $groups[$options['group']] = MessageGroups::getGroup( $options['group'] );
 81+} elseif( isset( $options['groups'] ) ) {
 82+ // Explode parameter
 83+ $groupIds = explode( ',', trim( $options['groups'] ) );
7984
80 -if ( $threshold ) {
81 - $langs = TranslationStats::getPercentageTranslated(
82 - $options['group'],
83 - $langs,
84 - $threshold,
85 - true
86 - );
 85+ // Get groups and add groups to array
 86+ foreach ( $groupIds as $groupId ) {
 87+ $groups[$groupId] = MessageGroups::getGroup( $groupId );
 88+ }
 89+} else {
 90+ // Apparently using option grouptrail. Find groups that match.
 91+ $allGroups = MessageGroups::singleton()->getGroups();
 92+
 93+ // Add matching groups to groups array.
 94+ foreach( $allGroups as $groupId => $messageGroup ) {
 95+ if( strpos( $groupId, $options['grouptrail'] ) === 0 && !$messageGroup->isMeta() ) {
 96+ $groups[$groupId] = $messageGroup;
 97+ }
 98+ }
8799 }
88100
89 -if ( $group instanceof FileBasedMessageGroup ) {
90 - $ffs = $group->getFFS();
91 - $ffs->setWritePath( $options['target'] );
92 - $collection = $group->initCollection( 'en' );
 101+foreach( $groups as $groupId => $group ) {
 102+ if ( !$group instanceof MessageGroup ) {
 103+ STDERR( "Invalid group: " . $groupId );
 104+ exit( 1 );
 105+ }
93106
94 - $definitionFile = false;
 107+ if ( $threshold ) {
 108+ $langs = TranslationStats::getPercentageTranslated(
 109+ $groupId,
 110+ $langs,
 111+ $threshold,
 112+ true
 113+ );
 114+ }
95115
96 - if ( isset( $options['ppgettext'] ) && $ffs instanceof GettextFFS ) {
97 - global $wgMaxShellMemory;
 116+ STDERR( 'Exporting ' . $groupId );
98117
99 - // Need more shell memory for msgmerge.
100 - $wgMaxShellMemory = 302400;
 118+ if ( $group instanceof FileBasedMessageGroup ) {
 119+ $ffs = $group->getFFS();
 120+ $ffs->setWritePath( $options['target'] );
 121+ $collection = $group->initCollection( 'en' );
101122
102 - $conf = $group->getConfiguration();
103 - $definitionFile = str_replace( '%GROUPROOT%', $options['ppgettext'], $conf['FILES']['definitionFile'] );
104 - }
 123+ $definitionFile = false;
105124
106 - foreach ( $langs as $lang ) {
107 - // Do not export if language code is to be skipped.
108 - if( in_array( $lang, $skip ) && !$group->isValidLanguage( $lang ) ) {
109 - continue;
 125+ if ( isset( $options['ppgettext'] ) && $ffs instanceof GettextFFS ) {
 126+ global $wgMaxShellMemory;
 127+
 128+ // Need more shell memory for msgmerge.
 129+ $wgMaxShellMemory = 302400;
 130+
 131+ $conf = $group->getConfiguration();
 132+ $definitionFile = str_replace( '%GROUPROOT%', $options['ppgettext'], $conf['FILES']['definitionFile'] );
110133 }
111134
112 - $collection->resetForNewLanguage( $lang );
113 - $ffs->write( $collection );
 135+ foreach ( $langs as $lang ) {
 136+ // Do not export if language code is to be skipped.
 137+ if( in_array( $lang, $skip ) && !$group->isValidLanguage( $lang ) ) {
 138+ continue;
 139+ }
114140
115 - // Do post processing if requested.
116 - if ( $definitionFile ) {
117 - if ( is_file( $definitionFile ) ) {
118 - $targetFileName = $ffs->getWritePath() . $group->getTargetFilename( $collection->code );
119 - $cmd = "msgmerge --quiet --update --backup=off " . $targetFileName . ' ' . $definitionFile;
120 - wfShellExec( $cmd, $ret );
 141+ $collection->resetForNewLanguage( $lang );
 142+ $ffs->write( $collection );
121143
122 - // Report on errors.
123 - if ( $ret ) {
124 - STDERR( 'ERROR: ' . $ret );
 144+ // Do post processing if requested.
 145+ if ( $definitionFile ) {
 146+ if ( is_file( $definitionFile ) ) {
 147+ $targetFileName = $ffs->getWritePath() . $group->getTargetFilename( $collection->code );
 148+ $cmd = "msgmerge --quiet --update --backup=off " . $targetFileName . ' ' . $definitionFile;
 149+ wfShellExec( $cmd, $ret );
 150+
 151+ // Report on errors.
 152+ if ( $ret ) {
 153+ STDERR( 'ERROR: ' . $ret );
 154+ }
 155+ } else {
 156+ STDERR( $definitionFile . ' does not exist.' );
 157+ exit( 1 );
125158 }
126 - } else {
127 - STDERR( $definitionFile . ' does not exist.' );
128 - exit( 1 );
129159 }
130160 }
 161+ } else {
 162+ $writer = $group->getWriter();
 163+ $writer->fileExport( $langs, $options['target'] );
131164 }
132 -} else {
133 - $writer = $group->getWriter();
134 - $writer->fileExport( $langs, $options['target'] );
135165 }

Status & tagging log