From b59ddf11def660abf092a8348ddb5ef4c0c2d3f9 Mon Sep 17 00:00:00 2001 From: Markus Klein <klein.t3@reelworx.at> Date: Fri, 24 Oct 2014 02:01:52 +0200 Subject: [PATCH] [!!!][BUGFIX] Use decimal point of current locale Let GeneralUtility::formatSize use the current locale's information about number notation. This also influences the stdWrap.bytes TypoScript property. Resolves: #60152 Releases: master Change-Id: I878fffc6f8e8dd038848dd8cd5d7fd3e7fa57f3d Reviewed-on: http://review.typo3.org/33500 Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de> Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de> Reviewed-by: Stefan Froemken <froemken@gmail.com> Tested-by: Stefan Froemken <froemken@gmail.com> --- .../core/Classes/Utility/GeneralUtility.php | 16 ++++++++-- ...Breaking-60152-formatSizeAdheresLocale.rst | 31 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-60152-formatSizeAdheresLocale.rst diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 769dca7c764d..90b97c99a119 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -960,18 +960,28 @@ class GeneralUtility { $labelArr = explode('|', $labels); // Find size: if ($sizeInBytes > 900) { + // TODO find out which locale is used for current BE user to cover the BE case as well + $locale = is_object($GLOBALS['TSFE']) ? $GLOBALS['TSFE']->config['config']['locale_all'] : ''; + $oldLocale = setlocale(LC_NUMERIC, 0); + if ($locale) { + setlocale(LC_NUMERIC, $locale); + } + $localeInfo = localeconv(); + if ($locale) { + setlocale(LC_NUMERIC, $oldLocale); + } // GB if ($sizeInBytes > 900000000) { $val = $sizeInBytes / (1024 * 1024 * 1024); - return number_format($val, ($val < 20 ? 1 : 0), '.', '') . $labelArr[3]; + return number_format($val, ($val < 20 ? 1 : 0), $localeInfo['decimal_point'], '') . $labelArr[3]; } elseif ($sizeInBytes > 900000) { // MB $val = $sizeInBytes / (1024 * 1024); - return number_format($val, ($val < 20 ? 1 : 0), '.', '') . $labelArr[2]; + return number_format($val, ($val < 20 ? 1 : 0), $localeInfo['decimal_point'], '') . $labelArr[2]; } else { // KB $val = $sizeInBytes / 1024; - return number_format($val, ($val < 20 ? 1 : 0), '.', '') . $labelArr[1]; + return number_format($val, ($val < 20 ? 1 : 0), $localeInfo['decimal_point'], '') . $labelArr[1]; } } else { // Bytes diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-60152-formatSizeAdheresLocale.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-60152-formatSizeAdheresLocale.rst new file mode 100644 index 000000000000..11fc73cc428f --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-60152-formatSizeAdheresLocale.rst @@ -0,0 +1,31 @@ +================================================================= +Breaking: #60152 - GeneralUtility::formatSize is now locale aware +================================================================= + +Description +=========== + +The GeneralUtility::formatSize() method now adheres to the currently set locale and +selects the correct decimal separator symbol. +This also applies to the TypoScript option stdWrap.bytes, which uses the method internally, +as well as the Filelist content element type. + +Impact +====== + +All output generated for locales, where the decimal separator is not a dot, will change to use +the correct symbol. e.g. comma for German. + +Affected installations +====================== + +Any installation that uses the formatSize() method in one of the aforementioned ways. + +Migration +========= + +If you think you get the wrong decimal separator, ensure the locale is configured correctly +and the locale really exists on the server. + +TypoScript option: config.locale +Commandline: locale -a -- GitLab