From 5a7f309f754cbf61a432b73df3f5db412fef0d44 Mon Sep 17 00:00:00 2001 From: Oliver Hader <oliver@typo3.org> Date: Thu, 12 Mar 2015 14:27:24 +0100 Subject: [PATCH] [FEATURE] Add possibility to provide additional localization files 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> --- ...-AdditionalResourceServiceLocalization.rst | 17 ++++++++++++ .../Classes/Controller/ReviewController.php | 3 +++ .../Service/AdditionalResourceService.php | 27 +++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-65698-AdditionalResourceServiceLocalization.rst 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 index 000000000000..0026e48c3dd2 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-65698-AdditionalResourceServiceLocalization.rst @@ -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' + ); diff --git a/typo3/sysext/workspaces/Classes/Controller/ReviewController.php b/typo3/sysext/workspaces/Classes/Controller/ReviewController.php index 5bc30bd49f36..2d3f3e202772 100644 --- a/typo3/sysext/workspaces/Classes/Controller/ReviewController.php +++ b/typo3/sysext/workspaces/Classes/Controller/ReviewController.php @@ -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')); } diff --git a/typo3/sysext/workspaces/Classes/Service/AdditionalResourceService.php b/typo3/sysext/workspaces/Classes/Service/AdditionalResourceService.php index 2504d150c21d..d81197dec064 100644 --- a/typo3/sysext/workspaces/Classes/Service/AdditionalResourceService.php +++ b/typo3/sysext/workspaces/Classes/Service/AdditionalResourceService.php @@ -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 * @@ -31,6 +33,11 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface { */ protected $stylesheetResources = array(); + /** + * @var array + */ + protected $localizationResources = array(); + /** * @return \TYPO3\CMS\Workspaces\Service\AdditionalResourceService */ @@ -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); } /** @@ -63,6 +70,15 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface { $this->stylesheetResources[$name] = $this->resolvePath($resourcePath); } + /** + * @param string $resourcePath + * @return void + */ + public function addLocalizationResource($resourcePath) { + $absoluteResourcePath = GeneralUtility::getFileAbsFileName($resourcePath); + $this->localizationResources[$absoluteResourcePath] = $absoluteResourcePath; + } + /** * @return array */ @@ -77,6 +93,13 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface { return $this->stylesheetResources; } + /** + * @return array + */ + public function getLocalizationResources() { + return $this->localizationResources; + } + /** * Resolve path * @@ -84,7 +107,7 @@ class AdditionalResourceService implements \TYPO3\CMS\Core\SingletonInterface { * @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); -- GitLab