'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
'imageFiles', 'preloadedMessages', 'namespaceGenderAliases',
+ 'digitGroupingPattern'
);
/**
/**
* Adds commas to a given number
- *
+ * @since 1.19
* @param $_ mixed
* @return string
*/
function commafy( $_ ) {
- return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
+ $digitGroupingPattern = $this->digitGroupingPattern();
+
+ if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
+ //default grouping is at thousands, use the same for ###,###,### pattern too.
+ return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
+ }
+ else {
+ // Ref: http://cldr.unicode.org/translation/number-patterns
+ $numberpart = array();
+ $decimalpart = array();
+ $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches );
+ preg_match( "/\d+/", $_, $numberpart );
+ preg_match( "/\.\d*/", $_, $decimalpart );
+ $groupedNumber = ( count( $decimalpart ) > 0 ) ? $decimalpart[0]:"";
+ if ( $groupedNumber === $_){
+ //the string does not have any number part. Eg: .12345
+ return $groupedNumber;
+ }
+ $start = $end = strlen( $numberpart[0] );
+ while ( $start > 0 )
+ {
+ $match = $matches[0][$numMatches -1] ;
+ $matchLen = strlen( $match );
+ $start = $end - $matchLen;
+ if ( $start < 0 ) {
+ $start = 0;
+ }
+ $groupedNumber = substr( $_ , $start, $end -$start ) . $groupedNumber ;
+ $end = $start;
+ if ( $numMatches > 1 ) {
+ // use the last pattern for the rest of the number
+ $numMatches--;
+ }
+ if ( $start > 0 ) {
+ $groupedNumber = "," . $groupedNumber;
+ }
+ }
+ return $groupedNumber;
+ }
+ }
+ /**
+ * @return String
+ */
+ function digitGroupingPattern() {
+ return self::$dataCache->getItem( $this->mCode, 'digitGroupingPattern' );
}
/**
);
$linkTrail = "/^([a-z]+)(.*)$/sD";
+$digitGroupingPattern = "##,##,###";
+
$messages = array(
# User preference toggles
'tog-underline' => 'कड़ियाँ अधोरेखन:',
'url_query' => array( '0', 'ക്വറി', 'QUERY' ),
);
+$digitGroupingPattern = "##,##,###";
+
$messages = array(
# User preference toggles
'tog-underline' => 'കണ്ണികൾക്ക് അടിവരയിടുക:',
--- /dev/null
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2011, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageMl.php */
+class LanguageMlTest extends MediaWikiTestCase {
+ private $lang;
+
+ function setUp() {
+ $this->lang = Language::factory( 'Ml' );
+ }
+ function tearDown() {
+ unset( $this->lang );
+ }
+
+ /** see bug 29495 */
+ function testFormatNum() {
+ $this->assertEquals( '12,34,567', $this->lang->formatNum( '1234567' ) );
+ $this->assertEquals( '12,345', $this->lang->formatNum( '12345' ) );
+ $this->assertEquals( '1', $this->lang->formatNum( '1' ) );
+ $this->assertEquals( '123', $this->lang->formatNum( '123' ) );
+ $this->assertEquals( '1,234', $this->lang->formatNum( '1234' ) );
+ $this->assertEquals( '12,345.56', $this->lang->formatNum( '12345.56' ) );
+ $this->assertEquals( '12,34,56,79,81,23,45,678', $this->lang->formatNum( '12345679812345678' ) );
+ $this->assertEquals( '.12345', $this->lang->formatNum( '.12345' ) );
+ }
+}
--- /dev/null
+<?php
+/**
+ * @author Santhosh Thottingal
+ * @copyright Copyright © 2011, Santhosh Thottingal
+ * @file
+ */
+
+/** Tests for MediaWiki languages/LanguageNl.php */
+class LanguageNlTest extends MediaWikiTestCase {
+ private $lang;
+
+ function setUp() {
+ $this->lang = Language::factory( 'Nl' );
+ }
+ function tearDown() {
+ unset( $this->lang );
+ }
+
+ function testFormatNum() {
+ $this->assertEquals( '1.234.567', $this->lang->formatNum( '1234567' ) );
+ $this->assertEquals( '12.345', $this->lang->formatNum( '12345' ) );
+ $this->assertEquals( '1', $this->lang->formatNum( '1' ) );
+ $this->assertEquals( '123', $this->lang->formatNum( '123' ) );
+ $this->assertEquals( '1.234', $this->lang->formatNum( '1234' ) );
+ $this->assertEquals( '12.345,56', $this->lang->formatNum( '12345.56' ) );
+ $this->assertEquals( ',1234556', $this->lang->formatNum( '.1234556' ) );
+ }
+}