Index: trunk/extensions/Translate/scripts/tm-export.php |
— | — | @@ -3,7 +3,6 @@ |
4 | 4 | * Script to bootstrap translatetoolkit translation memory |
5 | 5 | * |
6 | 6 | * @author Niklas Laxstrom |
7 | | - * |
8 | 7 | * @copyright Copyright © 2010-2011, Niklas Laxström |
9 | 8 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 9 | * @file |
Index: trunk/extensions/Translate/scripts/sync-group.php |
— | — | @@ -46,10 +46,16 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | // In case both group and groupprefix would be set, MessageGroups::getGroups |
50 | | -// will give preference to groupIds. |
51 | | -$groupIds = isset( $options['group'] ) ? explode( ',', trim( $options['group'] ) ) : null; |
52 | | -$groupPrefix = isset( $options['groupprefix'] ) ? $options['groupprefix'] : null; |
53 | | -$groups = MessageGroups::singleton()->getGroups( $groupIds, $groupPrefix ); |
| 50 | +// will give preference to group. @TODO: get rid of groupprefix |
| 51 | +$groupIds = array(); |
| 52 | +if ( isset( $options['groupprefix'] ) ) { |
| 53 | + $groupIds[] = $options['groupprefix'] . '*'; |
| 54 | +} |
| 55 | +if ( isset( $options['group'] ) ) { |
| 56 | + $groupIds = explode( ',', trim( $options['group'] ) ); |
| 57 | +} |
| 58 | +$groupIds = MessageGroups::expandWildcards( $groupIds ); |
| 59 | +$groups = MessageGroups::getGroupsById( $groupIds ); |
54 | 60 | |
55 | 61 | if ( !count( $groups ) ) { |
56 | 62 | STDERR( "ESG2: No valid message groups identified." ); |
Index: trunk/extensions/Translate/scripts/export.php |
— | — | @@ -89,13 +89,19 @@ |
90 | 90 | $reqLangs = Cli::parseLanguageCodes( $options['lang'] ); |
91 | 91 | |
92 | 92 | // In case both group and groupprefix would be set, MessageGroups::getGroups |
93 | | -// will give preference to groupIds. |
94 | | -$groupIds = isset( $options['group'] ) ? explode( ',', trim( $options['group'] ) ) : null; |
95 | | -$groupPrefix = isset( $options['groupprefix'] ) ? $options['groupprefix'] : null; |
96 | | -$groups = MessageGroups::singleton()->getGroups( $groupIds, $groupPrefix ); |
| 93 | +// will give preference to group. @TODO: get rid of groupprefix |
| 94 | +$groupIds = array(); |
| 95 | +if ( isset( $options['groupprefix'] ) ) { |
| 96 | + $groupIds[] = $options['groupprefix'] . '*'; |
| 97 | +} |
| 98 | +if ( isset( $options['group'] ) ) { |
| 99 | + $groupIds = explode( ',', trim( $options['group'] ) ); |
| 100 | +} |
| 101 | +$groupIds = MessageGroups::expandWildcards( $groupIds ); |
| 102 | +$groups = MessageGroups::getGroupsById( $groupIds ); |
97 | 103 | |
98 | 104 | if ( !count( $groups ) ) { |
99 | | - STDERR( "No valid message groups identified." ); |
| 105 | + STDERR( "EE1: No valid message groups identified." ); |
100 | 106 | exit( 1 ); |
101 | 107 | } |
102 | 108 | |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -1299,7 +1299,7 @@ |
1300 | 1300 | * Get all enabled message groups. |
1301 | 1301 | * @return \array |
1302 | 1302 | */ |
1303 | | - public function getAllMessageGroups() { |
| 1303 | + public function getGroups() { |
1304 | 1304 | if ( $this->classes === null ) { |
1305 | 1305 | $this->classes = array(); |
1306 | 1306 | global $wgTranslateEC, $wgTranslateCC; |
— | — | @@ -1317,40 +1317,47 @@ |
1318 | 1318 | } |
1319 | 1319 | |
1320 | 1320 | /** |
1321 | | - * Get message groups. |
| 1321 | + * Get message groups for corresponding message group ids. |
1322 | 1322 | * |
1323 | | - * @para $groups \array Group IDs |
1324 | | - * @para $groupPrefix \string Prefix for groups |
1325 | | - * @return \array |
| 1323 | + * @param $groups array Group IDs |
| 1324 | + * @param $groupPrefix string Prefix for groups |
| 1325 | + * @return array |
| 1326 | + * @since 2012-02-13 |
1326 | 1327 | */ |
1327 | | - public function getGroups( $groups = null, $groupPrefix = null ) { |
1328 | | - if ( count( $groups ) ) { |
1329 | | - // Get groups and add groups to array |
1330 | | - foreach ( $groups as $groupId ) { |
1331 | | - $group = self::getGroup( $groupId ); |
| 1328 | + public static function getGroupsById( array $ids ) { |
| 1329 | + $groups = array(); |
| 1330 | + foreach ( $ids as $id ) { |
| 1331 | + $group = self::getGroup( $id ); |
1332 | 1332 | |
1333 | | - if ( $group !== null ) { |
1334 | | - $groups[$groupId] = $group; |
1335 | | - } else { |
1336 | | - wfDebug( __METHOD__ . ": Invalid group $groupId\n" ); |
1337 | | - } |
| 1333 | + if ( $group !== null ) { |
| 1334 | + $groups[$id] = $group; |
| 1335 | + } else { |
| 1336 | + wfDebug( __METHOD__ . ": Invalid message group id: $id\n" ); |
1338 | 1337 | } |
| 1338 | + } |
1339 | 1339 | |
1340 | | - return $groups; |
1341 | | - } elseif ( $groupPrefix !== null ) { |
1342 | | - $allGroups = self::singleton()->getGroups(); |
| 1340 | + return $groups; |
| 1341 | + } |
1343 | 1342 | |
1344 | | - // Add matching groups to groups array. |
1345 | | - foreach ( $allGroups as $groupId => $messageGroup ) { |
1346 | | - if ( strpos( $groupId, $groupPrefix ) === 0 && !$messageGroup->isMeta() ) { |
1347 | | - $groups[$groupId] = $messageGroup; |
1348 | | - } |
| 1343 | + /** |
| 1344 | + * If the list of message group ids contains wildcards, this function will match |
| 1345 | + * them against the list of all supported message groups and return matched |
| 1346 | + * message group ids. |
| 1347 | + * @param $ids \list{String}|String |
| 1348 | + * @return \list{String} |
| 1349 | + * @since 2012-02-13 |
| 1350 | + */ |
| 1351 | + public static function expandWildcards( $ids ) { |
| 1352 | + $all = array(); |
| 1353 | + |
| 1354 | + $matcher = new StringMatcher( '', (array) $ids ); |
| 1355 | + foreach ( self::singleton()->getGroups() as $id => $_ ) { |
| 1356 | + if ( $matcher->match( $id ) ) { |
| 1357 | + $all[] = $id; |
1349 | 1358 | } |
| 1359 | + } |
1350 | 1360 | |
1351 | | - return $groups; |
1352 | | - } else { |
1353 | | - return self::getAllMessageGroups(); |
1354 | | - } |
| 1361 | + return $all; |
1355 | 1362 | } |
1356 | 1363 | |
1357 | 1364 | /** |