*/
function commafy( $number ) {
$digitGroupingPattern = $this->digitGroupingPattern();
+ $minimumGroupingDigits = $this->minimumGroupingDigits();
if ( $number === null ) {
return '';
}
if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
- // default grouping is at thousands, use the same for ###,###,### pattern too.
+ // Default grouping is at thousands, use the same for ###,###,### pattern too.
+ // In some languages it's conventional not to insert a thousands separator
+ // in numbers that are four digits long (1000-9999).
+ if ( $minimumGroupingDigits ) {
+ // Number of '#' characters after last comma in the grouping pattern.
+ // The pattern is hardcoded here, but this would vary for different patterns.
+ $primaryGroupingSize = 3;
+ // Maximum length of a number to suppress digit grouping for.
+ $maximumLength = $minimumGroupingDigits + $primaryGroupingSize - 1;
+ if ( preg_match( '/^\-?\d{1,' . $maximumLength . '}(\.\d+)?$/', $number ) ) {
+ return $number;
+ }
+ }
return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $number ) ) );
} else {
// Ref: http://cldr.unicode.org/translation/number-patterns
return self::$dataCache->getItem( $this->mCode, 'separatorTransformTable' );
}
+ /**
+ * @return int|null
+ */
+ function minimumGroupingDigits() {
+ return self::$dataCache->getItem( $this->mCode, 'minimumGroupingDigits' );
+ }
+
/**
* Take a list of strings and build a locale-friendly comma-separated
* list, using the local comma-separator message.
* @return string
*/
function truncate( $string, $length, $ellipsis = '...', $adjustLength = true ) {
+ # Check if there is no need to truncate
+ if ( strlen( $string ) <= abs( $length ) ) {
+ return $string; // no need to truncate
+ }
# Use the localized ellipsis character
if ( $ellipsis == '...' ) {
$ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
}
- # Check if there is no need to truncate
if ( $length == 0 ) {
return $ellipsis; // convention
- } elseif ( strlen( $string ) <= abs( $length ) ) {
- return $string; // no need to truncate
}
$stringOriginal = $string;
# If ellipsis length is >= $length then we can't apply $adjustLength