[BUGFIX] Fluid BytesViewHelper: use translated units 97/38497/12
authorMichael Oehlhof <typo3@oehlhof.de>
Mon, 6 Apr 2015 15:18:25 +0000 (17:18 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 20 Jun 2015 12:30:50 +0000 (14:30 +0200)
The units are moved from a constant to a localization file,
to make it possible to translate the units.

Resolves: #62454
Releases: master
Change-Id: I57a8fd2a060173fd9acbe30e3e3c716efd3c3fd9
Reviewed-on: http://review.typo3.org/38497
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/fluid/Classes/ViewHelpers/Format/BytesViewHelper.php
typo3/sysext/fluid/Resources/Private/Language/locallang.xlf
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/BytesViewHelperTest.php

index 869b993..2ee81db 100644 (file)
@@ -11,6 +11,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
@@ -43,7 +45,7 @@ class BytesViewHelper extends AbstractViewHelper implements CompilableInterface
        /**
         * @var array
         */
-       static protected $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
+       static protected $units = array();
 
        /**
         * Render the supplied byte count as a human readable string.
@@ -82,6 +84,9 @@ class BytesViewHelper extends AbstractViewHelper implements CompilableInterface
                        $value = $renderChildrenClosure();
                }
 
+               if (empty(self::$units)) {
+                       self::$units = GeneralUtility::trimExplode(',', LocalizationUtility::translate('viewhelper.format.bytes.units', 'fluid'));
+               }
                if (!is_integer($value) && !is_float($value)) {
                        if (is_numeric($value)) {
                                $value = (float)$value;
index bd0262a..d4d5fcb 100644 (file)
@@ -24,6 +24,9 @@
                        <trans-unit id="widget.pagination.refresh">
                                <source>Refresh</source>
                        </trans-unit>
+                       <trans-unit id="viewhelper.format.bytes.units">
+                               <source>B,KB,MB,GB,TB,PB,EB,ZB,YB</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index d5ffa58..67e1ec9 100644 (file)
@@ -11,6 +11,7 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
 
 /**
@@ -25,6 +26,13 @@ class BytesViewHelperTest extends ViewHelperBaseTestcase {
 
        protected function setUp() {
                parent::setUp();
+
+               // XXX: This is bad from a testing POV but the only option right now
+               $reflectionClass = new \ReflectionClass(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::class);
+               $property = $reflectionClass->getProperty('configurationManager');
+               $property->setAccessible(TRUE);
+               $property->setValue($this->getMock(ConfigurationManagerInterface::class));
+
                $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\BytesViewHelper::class, array('renderChildren'));
                $this->injectDependenciesIntoViewHelper($this->viewHelper);
                $this->viewHelper->initializeArguments();