[FEATURE] Add possibility to provide additional localization files 89/37789/4
authorOliver Hader <oliver@typo3.org>
Thu, 12 Mar 2015 13:27:24 +0000 (14:27 +0100)
committerBenjamin Mack <benni@typo3.org>
Wed, 15 Jul 2015 09:54:47 +0000 (11:54 +0200)
The AdditionalResourceService of the workspace module in the
backend currently allows to define custom JavaScript and
stylesheet resources. However, adding custom localization
files is missing and topic of this change.

Resolves: #65698
Releases: master
Change-Id: Ic9a3f004408b2406ac0e08fa2c96550cf059e3e8
Reviewed-on: http://review.typo3.org/37789
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-65698-AdditionalResourceServiceLocalization.rst [new file with mode: 0644]
typo3/sysext/workspaces/Classes/Controller/ReviewController.php
typo3/sysext/workspaces/Classes/Service/AdditionalResourceService.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-65698-AdditionalResourceServiceLocalization.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-65698-AdditionalResourceServiceLocalization.rst
new file mode 100644 (file)
index 0000000..0026e48
--- /dev/null
@@ -0,0 +1,17 @@
+===========================================================================
+Feature: #65698 - Additional localization files in backend workspace module
+===========================================================================
+
+Description
+===========
+
+The AdditionalResourceService of the workspace module in the backend is extended
+by the functionality to register custom localization files that are forwarded to
+the PageRenderer in the end. This way, labels can be accessed in JavaScript using
+the TYPO3.l10n.localize() function for instance.
+
+.. code-block:: php
+
+       \TYPO3\CMS\Workspaces\Service\AdditionalResourceService::getInstance()->addLocalizationResource(
+               'EXT:my_extension/Resources/Private/Language/locallang.xlf'
+       );
index 5bc30bd..2d3f3e2 100644 (file)
@@ -192,6 +192,9 @@ class ReviewController extends AbstractController {
                foreach ($javaScriptFiles as $javaScriptFile) {
                        $this->pageRenderer->addJsFile($javaScriptFile);
                }
+               foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
+                       $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
+               }
                $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
        }
 
index 2504d15..d81197d 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Workspaces\Service;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Service for additional columns in GridPanel
  *
@@ -32,6 +34,11 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface {
        protected $stylesheetResources = array();
 
        /**
+        * @var array
+        */
+       protected $localizationResources = array();
+
+       /**
         * @return \TYPO3\CMS\Workspaces\Service\AdditionalResourceService
         */
        static public function getInstance() {
@@ -42,7 +49,7 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface {
         * @return \TYPO3\CMS\Extbase\Object\ObjectManager
         */
        static public function getObjectManager() {
-               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
+               return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
        }
 
        /**
@@ -64,6 +71,15 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * @param string $resourcePath
+        * @return void
+        */
+       public function addLocalizationResource($resourcePath) {
+               $absoluteResourcePath = GeneralUtility::getFileAbsFileName($resourcePath);
+               $this->localizationResources[$absoluteResourcePath] = $absoluteResourcePath;
+       }
+
+       /**
         * @return array
         */
        public function getJavaScriptResources() {
@@ -78,13 +94,20 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * @return array
+        */
+       public function getLocalizationResources() {
+               return $this->localizationResources;
+       }
+
+       /**
         * Resolve path
         *
         * @param string $resourcePath
         * @return NULL|string
         */
        protected function resolvePath($resourcePath) {
-               $absoluteFilePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($resourcePath);
+               $absoluteFilePath = GeneralUtility::getFileAbsFileName($resourcePath);
                $absolutePath = dirname($absoluteFilePath);
                $fileName = basename($absoluteFilePath);