From: Bryan Tong Minh Date: Sat, 22 Jan 2011 20:23:51 +0000 (+0000) Subject: Add automatic formatting of numeric parameters to Message X-Git-Tag: 1.31.0-rc.0~32431 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=269bf3c2397b7e253802ed5098bf51aa53df063f;p=lhc%2Fweb%2Fwiklou.git Add automatic formatting of numeric parameters to Message --- diff --git a/includes/Message.php b/includes/Message.php index 2a558f931e..9ee6eea51f 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -169,6 +169,20 @@ class Message { return $this; } + /** + * Add parameters that are numeric and will be passed through + * Language::formatNum before substitution + * @param Varargs: numeric parameters + * @return Message: $this + */ + public function numParams( /*...*/ ) { + $params = func_get_args(); + foreach( $params as $param ) { + $this->parameters[] = self::numParam( $param ); + } + return $this; + } + /** * Request the message in any language that is supported. * As a side effect interface message status is unconditionally @@ -328,6 +342,10 @@ class Message { public static function rawParam( $value ) { return array( 'raw' => $value ); } + + public static function numParam( $value ) { + return array( 'num' => $value ); + } /** * Substitutes any paramaters into the message text. @@ -342,6 +360,9 @@ class Message { $replacementKeys['$' . ($n + 1)] = $param; } elseif ( $type === 'after' && isset( $param['raw'] ) ) { $replacementKeys['$' . ($n + 1)] = $param['raw']; + } elseif ( isset( $param['num'] ) ) { + $replacementKeys['$' . ($n + 1)] = + $this->language->formatNum( $param['num'] ); } } $message = strtr( $message, $replacementKeys );