public static function formatBytes($bytes, $context, $precision, $languageCode = null)
{
$data = array('bytes' => $bytes, 'context' => $context, 'precision' => $precision, 'languageCode' => $languageCode);
$formattedBytes = ipJob('ipFormatBytes', $data);
if ($formattedBytes !== null) {
return $formattedBytes;
}
$sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
$decimal = array('au', 'bn', 'bw', 'ch', 'cn', 'do', 'eg', 'gt', 'hk', 'hn', 'ie', 'il', 'in', 'jp', 'ke', 'kp', 'kr', 'lb', 'lk', 'mn', 'mo', 'mt', 'mx', 'my', 'ng', 'ni', 'np', 'nz', 'pa', 'ph', 'pk', 'sg', 'th', 'tw', 'tz', 'ug', 'uk', 'us', 'zw');
if ($languageCode === null) {
$languageCode = ipContent()->getCurrentLanguage()->getCode();
}
for ($i = 0; $bytes >= 1024; $i++) {
$bytes /= 1024;
if ($i < 1) {
$bytes = round($bytes, 0);
} else {
$bytes = round($bytes, $precision);
}
}
if (in_array(strtolower($languageCode), $decimal)) {
$formattedBytes = $bytes;
} else {
$formattedBytes = str_replace('.', ',', $bytes);
}
$formattedBytes .= ' ' . $sizes[$i];
return $formattedBytes;
}