Index: trunk/extensions/I18nTags/I18nTags_body.php |
— | — | @@ -14,11 +14,24 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | public static function plural( $data, $params, $parser ) { |
18 | | - $n = isset($params['n']) ? intval($params['n']) : intval(rand()/rand()*1020); |
| 18 | + list( $from, $to ) = self::getRange( @$params['n'] ); |
19 | 19 | $args = explode('|', $data); |
20 | 20 | $lang = self::languageObject( $params ); |
21 | | - $t = $lang->convertPlural( $n, $args ); |
22 | | - return wfMsgReplaceArgs($t, array($n, 'NOT DEFINED')); |
| 21 | + |
| 22 | + $format = isset($params['format']) ? $params['format'] : '%s'; |
| 23 | + $format = str_replace( '\n', "\n", $format ); |
| 24 | + |
| 25 | + $s = ''; |
| 26 | + for( $i = $from; $i <= $to; $i++ ) { |
| 27 | + $t = $lang->convertPlural( $i, $args ); |
| 28 | + $fmtn = $lang->formatNum($i); |
| 29 | + $s .= str_replace( |
| 30 | + array( '%d', '%s'), |
| 31 | + array( $i, wfMsgReplaceArgs( $t, array($fmtn) ) ), |
| 32 | + $format |
| 33 | + ); |
| 34 | + } |
| 35 | + return $s; |
23 | 36 | } |
24 | 37 | |
25 | 38 | public static function linktrail( $data, $params, $parser ) { |
— | — | @@ -67,4 +80,21 @@ |
68 | 81 | global $wgContLang; |
69 | 82 | return isset( $params['lang'] ) ? Language::factory( $params['lang'] ) : $wgContLang; |
70 | 83 | } |
| 84 | + |
| 85 | + public static function getRange( $s, $min = false, $max = false) { |
| 86 | + $matches = array(); |
| 87 | + if ( preg_match( '/(\d+)-(\d+)/', $s, $matches ) ) { |
| 88 | + $from = $matches[1]; |
| 89 | + $to = $matches[2]; |
| 90 | + } else { |
| 91 | + $from = $to = (int) $s; |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + if ( $from > $to ) {$UNDEFINED = $to; $to = $from; $from = $UNDEFINED;} |
| 96 | + if ( $min !== false ) $from = max( $min, $from ); |
| 97 | + if ( $max !== false ) $to = min( $max, $to ); |
| 98 | + |
| 99 | + return array( $from, $to ); |
| 100 | + } |
71 | 101 | } |
\ No newline at end of file |
Index: trunk/extensions/I18nTags/I18nTags.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | 'description' => 'Access the i18n functions for number formatting, ' . |
17 | 17 | 'grammar and plural in any available language', |
18 | 18 | 'descriptionmsg' => 'i18ntags-desc', |
19 | | - 'version' => '2.2', |
| 19 | + 'version' => '2009-01-11', |
20 | 20 | 'author' => 'Niklas Laxström', |
21 | 21 | 'url' => 'http://www.mediawiki.org/wiki/Extension:I18nTags', |
22 | 22 | ); |