[BUGFIX] locallangXMLOverride hook has been removed
authorDominique Feyer <dominique.feyer@reelpeek.net>
Thu, 7 Jul 2011 23:29:41 +0000 (01:29 +0200)
committerXavier Perseguers <typo3@perseguers.ch>
Sun, 10 Jul 2011 08:02:57 +0000 (10:02 +0200)
This feature is back with a small addition. We can now override
a specific language only, with this configuration:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']
['fr']['EXT:aboutmodules/mod/locallang_mod.xml'][] = 'fileadmin/fr.locallang_mod.xml';

Change-Id: I0f92542305594c08d883462a4ce504da820e74dc
Resolves: #27923
Reviewed-on: http://review.typo3.org/3120
Reviewed-by: Stefan Neufeind
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
tests/t3lib/class.t3lib_divTest.php
typo3/sysext/lang/classes/class.tx_lang_factory.php
typo3/sysext/lang/classes/class.tx_lang_store.php

index 711ceab..78b6aef 100644 (file)
@@ -1740,15 +1740,26 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        // Set override file
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
 
+               /** @var $store tx_lang_Store */
+               $store = t3lib_div::makeInstance('tx_lang_Store');
+               $store->flushData('EXT:lang/locallang_core.xml');
+
+                       // Manually flush cache (because lang_l10n cannot be recreated automatically at this point)
+               $cacheDirectory = PATH_site . 'typo3temp/Cache/Data/lang_l10n/';
+               $cacheFiles = t3lib_div::getFilesInDir($cacheDirectory);
+               foreach ($cacheFiles as $cacheFile) {
+                       @unlink($cacheDirectory . $cacheFile);
+               }
+
                        // Get override value
                $overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
 
                        // Clean up again
                unlink($file);
 
-               $this->assertNotEquals($overrideLL['default']['buttons.logout'], '');
-               $this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']);
-               $this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT');
+               $this->assertNotEquals($overrideLL['default']['buttons.logout'][0]['target'], '');
+               $this->assertNotEquals($defaultLL['default']['buttons.logout'][0]['target'], $overrideLL['default']['buttons.logout'][0]['target']);
+               $this->assertEquals($overrideLL['default']['buttons.logout'][0]['target'], 'EXIT');
        }
 
 
index f9162b3..7951ff2 100644 (file)
@@ -111,11 +111,19 @@ class tx_lang_Factory implements t3lib_Singleton {
                        /** @var $parser tx_lang_parser */
                        $parser = $this->store->getParserInstance($fileReference);
 
+                               // Get parsed data
                        $LOCAL_LANG = $parser->getParsedData(
                                $this->store->getAbsoluteFileReference($fileReference),
                                $languageKey,
                                $charset
                        );
+
+                               // Override localization
+                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'])) {
+                               $this->localizationOverride($fileReference, $languageKey, $charset, $errorMode, $LOCAL_LANG);
+                       }
+
+                               // Save parsed data in cache
                        $this->store->setData(
                                $fileReference,
                                $languageKey,
@@ -123,13 +131,7 @@ class tx_lang_Factory implements t3lib_Singleton {
                        );
 
                                // Cache processed data
-                       $this->cacheInstance->set(
-                               $hash,
-                               $this->store->getDataByLanguage($fileReference, $languageKey),
-                               array(),
-                               $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['cache']['lifetime']
-                       );
-
+                       $this->cacheInstance->set($hash, $this->store->getDataByLanguage($fileReference, $languageKey));
                } catch (tx_lang_exception_FileNotFound $exception) {
                                // Source localization file not found
                        $this->store->setData($fileReference, $languageKey, array());
@@ -138,6 +140,42 @@ class tx_lang_Factory implements t3lib_Singleton {
                return $this->store->getData($fileReference);
        }
 
+       /**
+        * Override localization file
+        *
+        * This method merges the content of the override file with the default file
+        *
+        * @param string $fileReference
+        * @param string $languageKey
+        * @param string $charset
+        * @param integer $errorMode
+        * @param array $LOCAL_LANG
+        * @return void
+        */
+       protected function localizationOverride($fileReference, $languageKey, $charset, $errorMode, array &$LOCAL_LANG) {
+               $overrides = array();
+               $fileReferenceWithoutExtension = $this->store->getFileReferenceWithoutExtension($fileReference);
+
+               $locallangXMLOverride = $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'];
+               foreach ($this->store->getSupportedExtensions() as $extension) {
+                       if (isset($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension])) {
+                               $overrides = array_merge($overrides, $locallangXMLOverride[$languageKey][$fileReferenceWithoutExtension . '.' . $extension]);
+                       } elseif (isset($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]) && is_array($locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension])) {
+                               $overrides = array_merge($overrides, $locallangXMLOverride[$fileReferenceWithoutExtension . '.' . $extension]);
+                       }
+               }
+
+               if (count($overrides) > 0) {
+                       foreach ($overrides as $overrideFile) {
+                               $languageOverrideFileName = t3lib_div::getFileAbsFileName($overrideFile);
+                               $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule(
+                                       $LOCAL_LANG,
+                                       $this->getParsedData($languageOverrideFileName, $languageKey, $charset, $errorMode)
+                               );
+                       }
+               }
+       }
+
 }
 
 ?>
\ No newline at end of file
index 605e3ee..5acb10b 100644 (file)
@@ -130,6 +130,17 @@ class tx_lang_Store implements t3lib_Singleton {
        }
 
        /**
+        * Flushes data.
+        *
+        * @param string $fileReference
+        * @return tx_lang_Store This instance to allow method chaining
+        */
+       public function flushData($fileReference) {
+               unset($this->data[$fileReference]);
+               return $this;
+       }
+
+       /**
         * Checks file reference configuration (charset, extension, ...).
         *
         * @throws tx_lang_exception_InvalidParser|tx_lang_exception_FileNotFound
@@ -147,7 +158,7 @@ class tx_lang_Store implements t3lib_Singleton {
                        'charset' => $charset
                );
 
-               $fileWithoutExtension = t3lib_div::getFileAbsFileName(preg_replace('/\.[a-z0-9]+$/i' , '' , $fileReference));
+               $fileWithoutExtension = t3lib_div::getFileAbsFileName($this->getFileReferenceWithoutExtension($fileReference));
 
                foreach ($this->supportedExtensions as $extension) {
                        if (@is_file($fileWithoutExtension . '.' . $extension)) {
@@ -186,6 +197,19 @@ class tx_lang_Store implements t3lib_Singleton {
        }
 
        /**
+        * Get the filereference without the extension
+        *
+        * @param string $fileReference File reference
+        * @return string
+        */
+       public function getFileReferenceWithoutExtension($fileReference) {
+               if (!isset($this->configuration[$fileReference]['fileReferenceWithoutExtension'])) {
+                       $this->configuration[$fileReference]['fileReferenceWithoutExtension'] = preg_replace('/\.[a-z0-9]+$/i' , '' , $fileReference);
+               }
+               return $this->configuration[$fileReference]['fileReferenceWithoutExtension'];
+       }
+
+       /**
         * Returns the correct parser for a specific file reference.
         *
         * @throws tx_lang_exception_InvalidParser
@@ -222,6 +246,8 @@ class tx_lang_Store implements t3lib_Singleton {
        }
 
        /**
+        * Get supported extensions
+        *
         * @return array
         */
        public function getSupportedExtensions() {