Index: trunk/phase3/tests/phpunit/languages/LanguageMlTest.php |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Santhosh Thottingal |
| 5 | + * @copyright Copyright © 2011, Santhosh Thottingal |
| 6 | + * @file |
| 7 | + */ |
| 8 | + |
| 9 | +/** Tests for MediaWiki languages/LanguageMl.php */ |
| 10 | +class LanguageMlTest extends MediaWikiTestCase { |
| 11 | + private $lang; |
| 12 | + |
| 13 | + function setUp() { |
| 14 | + $this->lang = Language::factory( 'Ml' ); |
| 15 | + } |
| 16 | + function tearDown() { |
| 17 | + unset( $this->lang ); |
| 18 | + } |
| 19 | + |
| 20 | + /** see bug 29495 */ |
| 21 | + function testFormatNum() { |
| 22 | + $this->assertEquals( '12,34,567', $this->lang->formatNum( '1234567' ) ); |
| 23 | + $this->assertEquals( '12,345', $this->lang->formatNum( '12345' ) ); |
| 24 | + $this->assertEquals( '1', $this->lang->formatNum( '1' ) ); |
| 25 | + $this->assertEquals( '123', $this->lang->formatNum( '123' ) ); |
| 26 | + $this->assertEquals( '1,234', $this->lang->formatNum( '1234' ) ); |
| 27 | + $this->assertEquals( '12,345.56', $this->lang->formatNum( '12345.56' ) ); |
| 28 | + $this->assertEquals( '12,34,56,79,81,23,45,678', $this->lang->formatNum( '12345679812345678' ) ); |
| 29 | + $this->assertEquals( '.12345', $this->lang->formatNum( '.12345' ) ); |
| 30 | + } |
| 31 | +} |
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageMlTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 32 | + native |
Index: trunk/phase3/tests/phpunit/languages/LanguageNlTest.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Santhosh Thottingal |
| 5 | + * @copyright Copyright © 2011, Santhosh Thottingal |
| 6 | + * @file |
| 7 | + */ |
| 8 | + |
| 9 | +/** Tests for MediaWiki languages/LanguageNl.php */ |
| 10 | +class LanguageNlTest extends MediaWikiTestCase { |
| 11 | + private $lang; |
| 12 | + |
| 13 | + function setUp() { |
| 14 | + $this->lang = Language::factory( 'Nl' ); |
| 15 | + } |
| 16 | + function tearDown() { |
| 17 | + unset( $this->lang ); |
| 18 | + } |
| 19 | + |
| 20 | + function testFormatNum() { |
| 21 | + $this->assertEquals( '1.234.567', $this->lang->formatNum( '1234567' ) ); |
| 22 | + $this->assertEquals( '12.345', $this->lang->formatNum( '12345' ) ); |
| 23 | + $this->assertEquals( '1', $this->lang->formatNum( '1' ) ); |
| 24 | + $this->assertEquals( '123', $this->lang->formatNum( '123' ) ); |
| 25 | + $this->assertEquals( '1.234', $this->lang->formatNum( '1234' ) ); |
| 26 | + $this->assertEquals( '12.345,56', $this->lang->formatNum( '12345.56' ) ); |
| 27 | + $this->assertEquals( ',1234556', $this->lang->formatNum( '.1234556' ) ); |
| 28 | + } |
| 29 | +} |
Property changes on: trunk/phase3/tests/phpunit/languages/LanguageNlTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 30 | + native |
Index: trunk/phase3/includes/LocalisationCache.php |
— | — | @@ -88,6 +88,7 @@ |
89 | 89 | 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap', |
90 | 90 | 'defaultDateFormat', 'extraUserToggles', 'specialPageAliases', |
91 | 91 | 'imageFiles', 'preloadedMessages', 'namespaceGenderAliases', |
| 92 | + 'digitGroupingPattern' |
92 | 93 | ); |
93 | 94 | |
94 | 95 | /** |
Index: trunk/phase3/languages/messages/MessagesHi.php |
— | — | @@ -68,6 +68,8 @@ |
69 | 69 | ); |
70 | 70 | $linkTrail = "/^([a-z]+)(.*)$/sD"; |
71 | 71 | |
| 72 | +$digitGroupingPattern = "##,##,###"; |
| 73 | + |
72 | 74 | $messages = array( |
73 | 75 | # User preference toggles |
74 | 76 | 'tog-underline' => 'कड़ियाँ अधोरेखन:', |
Index: trunk/phase3/languages/messages/MessagesMl.php |
— | — | @@ -315,6 +315,8 @@ |
316 | 316 | 'url_query' => array( '0', 'ക്വറി', 'QUERY' ), |
317 | 317 | ); |
318 | 318 | |
| 319 | +$digitGroupingPattern = "##,##,###"; |
| 320 | + |
319 | 321 | $messages = array( |
320 | 322 | # User preference toggles |
321 | 323 | 'tog-underline' => 'കണ്ണികൾക്ക് അടിവരയിടുക:', |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -2606,13 +2606,57 @@ |
2607 | 2607 | |
2608 | 2608 | /** |
2609 | 2609 | * Adds commas to a given number |
2610 | | - * |
| 2610 | + * @since 1.19 |
2611 | 2611 | * @param $_ mixed |
2612 | 2612 | * @return string |
2613 | 2613 | */ |
2614 | 2614 | function commafy( $_ ) { |
2615 | | - return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); |
| 2615 | + $digitGroupingPattern = $this->digitGroupingPattern(); |
| 2616 | + |
| 2617 | + if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) { |
| 2618 | + //default grouping is at thousands, use the same for ###,###,### pattern too. |
| 2619 | + return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); |
| 2620 | + } |
| 2621 | + else { |
| 2622 | + // Ref: http://cldr.unicode.org/translation/number-patterns |
| 2623 | + $numberpart = array(); |
| 2624 | + $decimalpart = array(); |
| 2625 | + $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches ); |
| 2626 | + preg_match( "/\d+/", $_, $numberpart ); |
| 2627 | + preg_match( "/\.\d*/", $_, $decimalpart ); |
| 2628 | + $groupedNumber = ( count( $decimalpart ) > 0 ) ? $decimalpart[0]:""; |
| 2629 | + if ( $groupedNumber === $_){ |
| 2630 | + //the string does not have any number part. Eg: .12345 |
| 2631 | + return $groupedNumber; |
| 2632 | + } |
| 2633 | + $start = $end = strlen( $numberpart[0] ); |
| 2634 | + while ( $start > 0 ) |
| 2635 | + { |
| 2636 | + $match = $matches[0][$numMatches -1] ; |
| 2637 | + $matchLen = strlen( $match ); |
| 2638 | + $start = $end - $matchLen; |
| 2639 | + if ( $start < 0 ) { |
| 2640 | + $start = 0; |
| 2641 | + } |
| 2642 | + $groupedNumber = substr( $_ , $start, $end -$start ) . $groupedNumber ; |
| 2643 | + $end = $start; |
| 2644 | + if ( $numMatches > 1 ) { |
| 2645 | + // use the last pattern for the rest of the number |
| 2646 | + $numMatches--; |
| 2647 | + } |
| 2648 | + if ( $start > 0 ) { |
| 2649 | + $groupedNumber = "," . $groupedNumber; |
| 2650 | + } |
| 2651 | + } |
| 2652 | + return $groupedNumber; |
| 2653 | + } |
2616 | 2654 | } |
| 2655 | + /** |
| 2656 | + * @return String |
| 2657 | + */ |
| 2658 | + function digitGroupingPattern() { |
| 2659 | + return self::$dataCache->getItem( $this->mCode, 'digitGroupingPattern' ); |
| 2660 | + } |
2617 | 2661 | |
2618 | 2662 | /** |
2619 | 2663 | * @return array |