[FEATURE] Allow AbstractPlugin::pi_loadLL to load custom language file 34/42934/7
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Sun, 30 Aug 2015 20:32:30 +0000 (22:32 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 1 Sep 2015 08:29:53 +0000 (10:29 +0200)
Add optional parameter to pi_loadlLL method to allow loading
language files located somewhere else than $this->scriptRelPath folder.
This change allows to place language files in Resources/Private/Language
also in pi-based plugins.

Resolves: #69416
Releases: master
Change-Id: Ibcfef65b1606a86559f17e706f8873a2c5a3973b
Reviewed-on: http://review.typo3.org/42934
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-69416-MakeAbstractPluginpi_loadLLLoadLabelsFromCustomFile.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-69416-MakeAbstractPluginpi_loadLLLoadLabelsFromCustomFile.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-69416-MakeAbstractPluginpi_loadLLLoadLabelsFromCustomFile.rst
new file mode 100644 (file)
index 0000000..7481624
--- /dev/null
@@ -0,0 +1,14 @@
+========================================================================
+Feature: #69416 - Plugins (AbstractPlugin) can load custom language file
+========================================================================
+
+Description
+===========
+
+``AbstractPlugin::pi_loadLL`` takes an optional argument specifing path to a language file. It allows placing language files in other paths like in Extbase structure "Resources/Private/Language". Previously language file had to be located in the directory set in the ``scriptRelPath`` property.
+
+
+Impact
+======
+
+Possibility to put language label files in other paths.
index b4a9cff..08da6e7 100644 (file)
@@ -971,25 +971,32 @@ class AbstractPlugin {
        }
 
        /**
-        * Loads local-language values by looking for a "locallang" file in the
-        * plugin class directory ($this->scriptRelPath) and if found includes it.
+        * Loads local-language values from the file passed as a parameter or
+        * by looking for a "locallang" file in the
+        * plugin class directory ($this->scriptRelPath).
         * Also locallang values set in the TypoScript property "_LOCAL_LANG" are
         * merged onto the values found in the "locallang" file.
         * Supported file extensions xlf, xml
         *
+        * @param string $languageFilePath path to the plugin language file in format EXT:....
         * @return void
         */
-       public function pi_loadLL() {
-               if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
+       public function pi_loadLL($languageFilePath = '') {
+               if ($this->LOCAL_LANG_loaded) {
+                       return;
+               }
+
+               if ($languageFilePath === '' && $this->scriptRelPath) {
+                       $languageFilePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xlf';
+               }
+               if ($languageFilePath !== '') {
                        /** @var $languageFactory LocalizationFactory */
                        $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
-
-                       $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xlf';
                        // Read the strings in the required charset (since TYPO3 4.2)
-                       $this->LOCAL_LANG = $languageFactory->getParsedData($basePath, $this->LLkey, $this->frontendController->renderCharset);
+                       $this->LOCAL_LANG = $languageFactory->getParsedData($languageFilePath, $this->LLkey, $this->frontendController->renderCharset);
                        $alternativeLanguageKeys = GeneralUtility::trimExplode(',', $this->altLLkey, TRUE);
                        foreach ($alternativeLanguageKeys as $languageKey) {
-                               $tempLL = $languageFactory->getParsedData($basePath, $languageKey);
+                               $tempLL = $languageFactory->getParsedData($languageFilePath, $languageKey);
                                if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) {
                                        $this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey];
                                }