Index: trunk/phase3/languages/Language.php |
— | — | @@ -3816,29 +3816,41 @@ |
3817 | 3817 | * @return string |
3818 | 3818 | */ |
3819 | 3819 | function formatBitrate( $bps ) { |
3820 | | - if ( $bps <= 0 ) { |
3821 | | - return str_replace( '$1', $this->formatNum( $bps ), $this->getMessageFromDB( 'bitrate-bits' ) ); |
| 3820 | + return $this->formatComputingNumbers( $bps, 1000, "bitrate-$1bits" ); |
| 3821 | + } |
| 3822 | + |
| 3823 | + /** |
| 3824 | + * @param $size int Size of the unit |
| 3825 | + * @param $boundary int Size boundary (1000, or 1024 in most cases) |
| 3826 | + * @param $messageKey string Message key to be uesd |
| 3827 | + * @return string |
| 3828 | + */ |
| 3829 | + function formatComputingNumbers( $size, $boundary, $messageKey ) { |
| 3830 | + if ( $size <= 0 ) { |
| 3831 | + return str_replace( '$1', $this->formatNum( $size ), |
| 3832 | + $this->getMessageFromDB( str_replace( '$1', '', $messageKey ) ) |
| 3833 | + ); |
3822 | 3834 | } |
3823 | | - $units = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ); |
| 3835 | + $sizes = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ); |
3824 | 3836 | $index = 0; |
3825 | 3837 | |
3826 | | - $maxIndex = count( $units ) - 1; |
3827 | | - while ( $bps >= 1000 && $index < $maxIndex ) { |
| 3838 | + $maxIndex = count( $sizes ) - 1; |
| 3839 | + while ( $size >= $boundary && $index < $maxIndex ) { |
3828 | 3840 | $index++; |
3829 | | - $bps /= 1000; |
| 3841 | + $size /= $boundary; |
3830 | 3842 | } |
3831 | 3843 | |
3832 | | - // For small units no decimal places necessary |
| 3844 | + // For small sizes no decimal places necessary |
3833 | 3845 | $round = 0; |
3834 | 3846 | if ( $index > 1 ) { |
3835 | 3847 | // For MB and bigger two decimal places are smarter |
3836 | 3848 | $round = 2; |
3837 | 3849 | } |
3838 | | - $msg = "bitrate-{$units[$index]}bits"; |
| 3850 | + $msg = str_replace( '$1', $messageKey, $sizes[$index] ); |
3839 | 3851 | |
3840 | | - $bps = round( $bps, $round ); |
| 3852 | + $size = round( $size, $round ); |
3841 | 3853 | $text = $this->getMessageFromDB( $msg ); |
3842 | | - return str_replace( '$1', $this->formatNum( $bps ), $text ); |
| 3854 | + return str_replace( '$1', $this->formatNum( $size ), $text ); |
3843 | 3855 | } |
3844 | 3856 | |
3845 | 3857 | /** |
— | — | @@ -3849,26 +3861,7 @@ |
3850 | 3862 | * @return string Plain text (not HTML) |
3851 | 3863 | */ |
3852 | 3864 | function formatSize( $size ) { |
3853 | | - $sizes = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ); |
3854 | | - $index = 0; |
3855 | | - |
3856 | | - $maxIndex = count( $sizes ) - 1; |
3857 | | - while ( $size >= 1024 && $index < $maxIndex ) { |
3858 | | - $index++; |
3859 | | - $size /= 1024; |
3860 | | - } |
3861 | | - |
3862 | | - // For small sizes no decimal places necessary |
3863 | | - $round = 0; |
3864 | | - if ( $index > 1 ) { |
3865 | | - // For MB and bigger two decimal places are smarter |
3866 | | - $round = 2; |
3867 | | - } |
3868 | | - $msg = "size-{$sizes[$index]}bytes"; |
3869 | | - |
3870 | | - $size = round( $size, $round ); |
3871 | | - $text = $this->getMessageFromDB( $msg ); |
3872 | | - return str_replace( '$1', $this->formatNum( $size ), $text ); |
| 3865 | + return $this->formatComputingNumbers( $size, 1024, "size-$1bytes" ); |
3873 | 3866 | } |
3874 | 3867 | |
3875 | 3868 | /** |