Index: trunk/extensions/Translate/scripts/export.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | * @file |
11 | 11 | */ |
12 | 12 | |
13 | | -$optionsWithArgs = array( 'lang', 'skip', 'target', 'group', 'threshold', 'ppgettext' ); |
| 13 | +$optionsWithArgs = array( 'lang', 'skip', 'target', 'group', 'groups', 'grouptrail', 'threshold', 'ppgettext' ); |
14 | 14 | require( dirname( __FILE__ ) . '/cli.inc' ); |
15 | 15 | |
16 | 16 | function showUsage() { |
— | — | @@ -22,7 +22,10 @@ |
23 | 23 | --target Target directory for exported files |
24 | 24 | --lang Comma separated list of language codes or * |
25 | 25 | --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) |
27 | 30 | --threshold Do not export under this percentage translated |
28 | 31 | --ppgettext Group root path for checkout of product. "msgmerge" will post |
29 | 32 | process on the export result based on the current definitionFile |
— | — | @@ -52,8 +55,8 @@ |
53 | 56 | $skip = array(); |
54 | 57 | } |
55 | 58 | |
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'" ); |
58 | 61 | exit( 1 ); |
59 | 62 | } |
60 | 63 | |
— | — | @@ -61,6 +64,7 @@ |
62 | 65 | STDERR( "Target directory is not writable (" . $options['target'] . ")" ); |
63 | 66 | exit( 1 ); |
64 | 67 | } |
| 68 | + |
65 | 69 | if ( isset( $options['threshold'] ) && intval( $options['threshold'] ) ) { |
66 | 70 | $threshold = $options['threshold']; |
67 | 71 | } else { |
— | — | @@ -69,66 +73,92 @@ |
70 | 74 | |
71 | 75 | $langs = Cli::parseLanguageCodes( $options['lang'] ); |
72 | 76 | |
73 | | -$group = MessageGroups::getGroup( $options['group'] ); |
| 77 | +$groups = array(); |
74 | 78 | |
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'] ) ); |
79 | 84 | |
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 | + } |
87 | 99 | } |
88 | 100 | |
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 | + } |
93 | 106 | |
94 | | - $definitionFile = false; |
| 107 | + if ( $threshold ) { |
| 108 | + $langs = TranslationStats::getPercentageTranslated( |
| 109 | + $groupId, |
| 110 | + $langs, |
| 111 | + $threshold, |
| 112 | + true |
| 113 | + ); |
| 114 | + } |
95 | 115 | |
96 | | - if ( isset( $options['ppgettext'] ) && $ffs instanceof GettextFFS ) { |
97 | | - global $wgMaxShellMemory; |
| 116 | + STDERR( 'Exporting ' . $groupId ); |
98 | 117 | |
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' ); |
101 | 122 | |
102 | | - $conf = $group->getConfiguration(); |
103 | | - $definitionFile = str_replace( '%GROUPROOT%', $options['ppgettext'], $conf['FILES']['definitionFile'] ); |
104 | | - } |
| 123 | + $definitionFile = false; |
105 | 124 | |
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'] ); |
110 | 133 | } |
111 | 134 | |
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 | + } |
114 | 140 | |
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 ); |
121 | 143 | |
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 ); |
125 | 158 | } |
126 | | - } else { |
127 | | - STDERR( $definitionFile . ' does not exist.' ); |
128 | | - exit( 1 ); |
129 | 159 | } |
130 | 160 | } |
| 161 | + } else { |
| 162 | + $writer = $group->getWriter(); |
| 163 | + $writer->fileExport( $langs, $options['target'] ); |
131 | 164 | } |
132 | | -} else { |
133 | | - $writer = $group->getWriter(); |
134 | | - $writer->fileExport( $langs, $options['target'] ); |
135 | 165 | } |