Updating number helper to allow output of main currency symbol in the 'after' slot. Also added some basic i18n for NumberHelper::toReadableSize Fixes #6150.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8069 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
jperras 2009-03-03 15:32:12 +00:00
parent d9cbb85488
commit 79cba70758
2 changed files with 14 additions and 7 deletions

View file

@ -54,19 +54,19 @@ class NumberHelper extends AppHelper {
function toReadableSize($size) { function toReadableSize($size) {
switch ($size) { switch ($size) {
case 0: case 0:
return '0 Bytes'; return __('0 Bytes', true);
case 1: case 1:
return '1 Byte'; return __('1 Byte', true);
case $size < 1024: case $size < 1024:
return $size . ' Bytes'; return $size . __(' Bytes', true);
case round($size / 1024) < 1024: case round($size / 1024) < 1024:
return $this->precision($size / 1024, 0) . ' KB'; return $this->precision($size / 1024, 0) . __(' KB', true);
case round($size / 1024 / 1024, 2) < 1024: case round($size / 1024 / 1024, 2) < 1024:
return $this->precision($size / 1024 / 1024, 2) . ' MB'; return $this->precision($size / 1024 / 1024, 2) . __(' MB', true);
case round($size / 1024 / 1024 / 1024, 2) < 1024: case round($size / 1024 / 1024 / 1024, 2) < 1024:
return $this->precision($size / 1024 / 1024 / 1024, 2) . ' GB'; return $this->precision($size / 1024 / 1024 / 1024, 2) . __(' GB', true);
default: default:
return $this->precision($size / 1024 / 1024 / 1024 / 1024, 2) . ' TB'; return $this->precision($size / 1024 / 1024 / 1024 / 1024, 2) . __(' TB', true);
} }
} }
/** /**
@ -172,6 +172,8 @@ class NumberHelper extends AppHelper {
$number = $number * $multiply; $number = $number * $multiply;
$options['before'] = null; $options['before'] = null;
$options['places'] = null; $options['places'] = null;
} elseif (empty($options['before'])) {
$options['before'] = null;
} else { } else {
$options['after'] = null; $options['after'] = null;
} }

View file

@ -97,6 +97,11 @@ class NumberTest extends CakeTestCase {
$result = $this->Number->currency($value, 'GBP'); $result = $this->Number->currency($value, 'GBP');
$expected = '&#163;100,100,100.00'; $expected = '&#163;100,100,100.00';
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$result = $this->Number->currency($value, '', array('thousands' =>' ', 'after' => '€', 'decimals' => ',', 'zero' => 'Gratuit'));
$expected = '100 100 100,00€';
$this->assertEqual($expected, $result);
} }
/** /**
* testCurrencyPositive method * testCurrencyPositive method