Skip to content

Commit

Permalink
Refactoring NumberHelper::toReadableSize to properly use I18n functio…
Browse files Browse the repository at this point in the history
…nality.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8071 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
jperras committed Mar 3, 2009
1 parent 0888158 commit 571f578
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions cake/libs/view/helpers/number.php
Expand Up @@ -52,21 +52,17 @@ function precision($number, $precision = 3) {
* @static
*/
function toReadableSize($size) {
switch ($size) {
case 0:
return __('0 Bytes', true);
case 1:
return __('1 Byte', true);
switch (true) {
case $size < 1024:
return $size . __(' Bytes', true);
return sprintf(__n('%d Byte', '%d Bytes', $size, true), $size);
case round($size / 1024) < 1024:
return $this->precision($size / 1024, 0) . __(' KB', true);
return sprintf(__('%d KB', true), $this->precision($size / 1024, 0));
case round($size / 1024 / 1024, 2) < 1024:
return $this->precision($size / 1024 / 1024, 2) . __(' MB', true);
return sprintf(__('%.2f MB', true), $this->precision($size / 1024 / 1024, 2));
case round($size / 1024 / 1024 / 1024, 2) < 1024:
return $this->precision($size / 1024 / 1024 / 1024, 2) . __(' GB', true);
return sprintf(__('%.2f GB', true), $this->precision($size / 1024 / 1024 / 1024, 2));
default:
return $this->precision($size / 1024 / 1024 / 1024 / 1024, 2) . __(' TB', true);
return sprintf(__('%.2f TB', true), $this->precision($size / 1024 / 1024 / 1024 / 1024, 2));
}
}
/**
Expand Down

0 comments on commit 571f578

Please sign in to comment.