http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73890
Revision: 73890
Author: siebrand
Date: 2010-09-28 14:27:02 +0000 (Tue, 28 Sep 2010)
Log Message:
-----------
All exporting multiple non-meta message groups using --groups or --grouptrail.
Modified Paths:
--------------
trunk/extensions/Translate/scripts/export.php
Modified: trunk/extensions/Translate/scripts/export.php
===================================================================
--- trunk/extensions/Translate/scripts/export.php 2010-09-28 14:11:10 UTC
(rev 73889)
+++ trunk/extensions/Translate/scripts/export.php 2010-09-28 14:27:02 UTC
(rev 73890)
@@ -9,7 +9,7 @@
* @file
*/
-$optionsWithArgs = array( 'lang', 'skip', 'target', 'group', 'threshold',
'ppgettext' );
+$optionsWithArgs = array( 'lang', 'skip', 'target', 'group', 'groups',
'grouptrail', 'threshold', 'ppgettext' );
require( dirname( __FILE__ ) . '/cli.inc' );
function showUsage() {
@@ -22,7 +22,10 @@
--target Target directory for exported files
--lang Comma separated list of language codes or *
--skip Languages to skip, comma separated list
- --group Group ID
+ --group Group ID (cannot use groups grouptrial)
+ --groups Group IDs, comma separated list (cannot use group or
grouptrial)
+ --grouptrail Trial for IDs of to be exported message groups (cannot use
+ group or grouptrial)
--threshold Do not export under this percentage translated
--ppgettext Group root path for checkout of product. "msgmerge" will post
process on the export result based on the current
definitionFile
@@ -52,8 +55,8 @@
$skip = array();
}
-if ( !isset( $options['group'] ) ) {
- STDERR( "You need to specify group" );
+if ( !isset( $options['group'] ) && !isset( $options['groups'] ) && !isset(
$options['grouptrail'] ) ) {
+ STDERR( "You need to specify one or more groups using any of the
options 'group', 'groups' or 'grouptrail'" );
exit( 1 );
}
@@ -61,6 +64,7 @@
STDERR( "Target directory is not writable (" . $options['target'] . ")"
);
exit( 1 );
}
+
if ( isset( $options['threshold'] ) && intval( $options['threshold'] ) ) {
$threshold = $options['threshold'];
} else {
@@ -69,66 +73,92 @@
$langs = Cli::parseLanguageCodes( $options['lang'] );
-$group = MessageGroups::getGroup( $options['group'] );
+$groups = array();
-if ( !$group instanceof MessageGroup ) {
- STDERR( "Invalid group: " . $options['group'] );
- exit( 1 );
-}
+if( isset( $options['group'] ) ) {
+ $groups[$options['group']] = MessageGroups::getGroup( $options['group']
);
+} elseif( isset( $options['groups'] ) ) {
+ // Explode parameter
+ $groupIds = explode( ',', trim( $options['groups'] ) );
-if ( $threshold ) {
- $langs = TranslationStats::getPercentageTranslated(
- $options['group'],
- $langs,
- $threshold,
- true
- );
+ // Get groups and add groups to array
+ foreach ( $groupIds as $groupId ) {
+ $groups[$groupId] = MessageGroups::getGroup( $groupId );
+ }
+} else {
+ // Apparently using option grouptrail. Find groups that match.
+ $allGroups = MessageGroups::singleton()->getGroups();
+
+ // Add matching groups to groups array.
+ foreach( $allGroups as $groupId => $messageGroup ) {
+ if( strpos( $groupId, $options['grouptrail'] ) === 0 &&
!$messageGroup->isMeta() ) {
+ $groups[$groupId] = $messageGroup;
+ }
+ }
}
-if ( $group instanceof FileBasedMessageGroup ) {
- $ffs = $group->getFFS();
- $ffs->setWritePath( $options['target'] );
- $collection = $group->initCollection( 'en' );
+foreach( $groups as $groupId => $group ) {
+ if ( !$group instanceof MessageGroup ) {
+ STDERR( "Invalid group: " . $groupId );
+ exit( 1 );
+ }
- $definitionFile = false;
+ if ( $threshold ) {
+ $langs = TranslationStats::getPercentageTranslated(
+ $groupId,
+ $langs,
+ $threshold,
+ true
+ );
+ }
- if ( isset( $options['ppgettext'] ) && $ffs instanceof GettextFFS ) {
- global $wgMaxShellMemory;
+ STDERR( 'Exporting ' . $groupId );
- // Need more shell memory for msgmerge.
- $wgMaxShellMemory = 302400;
+ if ( $group instanceof FileBasedMessageGroup ) {
+ $ffs = $group->getFFS();
+ $ffs->setWritePath( $options['target'] );
+ $collection = $group->initCollection( 'en' );
- $conf = $group->getConfiguration();
- $definitionFile = str_replace( '%GROUPROOT%',
$options['ppgettext'], $conf['FILES']['definitionFile'] );
- }
+ $definitionFile = false;
- foreach ( $langs as $lang ) {
- // Do not export if language code is to be skipped.
- if( in_array( $lang, $skip ) && !$group->isValidLanguage( $lang
) ) {
- continue;
+ if ( isset( $options['ppgettext'] ) && $ffs instanceof
GettextFFS ) {
+ global $wgMaxShellMemory;
+
+ // Need more shell memory for msgmerge.
+ $wgMaxShellMemory = 302400;
+
+ $conf = $group->getConfiguration();
+ $definitionFile = str_replace( '%GROUPROOT%',
$options['ppgettext'], $conf['FILES']['definitionFile'] );
}
- $collection->resetForNewLanguage( $lang );
- $ffs->write( $collection );
+ foreach ( $langs as $lang ) {
+ // Do not export if language code is to be skipped.
+ if( in_array( $lang, $skip ) &&
!$group->isValidLanguage( $lang ) ) {
+ continue;
+ }
- // Do post processing if requested.
- if ( $definitionFile ) {
- if ( is_file( $definitionFile ) ) {
- $targetFileName = $ffs->getWritePath() .
$group->getTargetFilename( $collection->code );
- $cmd = "msgmerge --quiet --update --backup=off
" . $targetFileName . ' ' . $definitionFile;
- wfShellExec( $cmd, $ret );
+ $collection->resetForNewLanguage( $lang );
+ $ffs->write( $collection );
- // Report on errors.
- if ( $ret ) {
- STDERR( 'ERROR: ' . $ret );
+ // Do post processing if requested.
+ if ( $definitionFile ) {
+ if ( is_file( $definitionFile ) ) {
+ $targetFileName = $ffs->getWritePath()
. $group->getTargetFilename( $collection->code );
+ $cmd = "msgmerge --quiet --update
--backup=off " . $targetFileName . ' ' . $definitionFile;
+ wfShellExec( $cmd, $ret );
+
+ // Report on errors.
+ if ( $ret ) {
+ STDERR( 'ERROR: ' . $ret );
+ }
+ } else {
+ STDERR( $definitionFile . ' does not
exist.' );
+ exit( 1 );
}
- } else {
- STDERR( $definitionFile . ' does not exist.' );
- exit( 1 );
}
}
+ } else {
+ $writer = $group->getWriter();
+ $writer->fileExport( $langs, $options['target'] );
}
-} else {
- $writer = $group->getWriter();
- $writer->fileExport( $langs, $options['target'] );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs