[BUGFIX] L10n fallback does not work for TS labels 70/18270/2
authorXavier Perseguers <xavier@typo3.org>
Thu, 20 Dec 2012 06:59:15 +0000 (07:59 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 14 Feb 2013 15:13:26 +0000 (16:13 +0100)
When retrieving a label in TypoScript in a locale that is not
available locally, the English label is returned instead of
using the locale fallback mechanism introduced in TYPO3 4.6.

Change-Id: I29f4b25e3fc23497d6afe74659810ca8995a39df
Fixes: #44099
Relates: #41996
Releases: 4.6, 4.7, 6.0, 6.1
Reviewed-on: https://review.typo3.org/17247
Reviewed-by: Mattias Nilsson
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-on: https://review.typo3.org/18270

typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

index 81c6f91..78c7cc5 100644 (file)
@@ -713,6 +713,14 @@ class TypoScriptFrontendController {
        public $LL_files_cache = array();
 
        /**
+        * List of language dependencies for actual language. This is used for local variants of a language
+        * that depend on their "main" language, like Brazilian Portuguese or Canadian French.
+        *
+        * @var array
+        */
+       protected $languageDependencies = array();
+
+       /**
         * Locking object for accessing "cache_pagesection"
         *
         * @var \TYPO3\CMS\Core\Locking\Locker
@@ -4598,7 +4606,31 @@ if (version == "n3") {
         * @todo Define visibility
         */
        public function readLLfile($fileRef) {
-               return \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile($fileRef, $this->lang, $this->renderCharset);
+               if ($this->lang !== 'default') {
+                       $languages = array_reverse($this->languageDependencies);
+                       // At least we need to have English
+                       if (empty($languages)) {
+                               $languages[] = 'default';
+                       }
+               } else {
+                       $languages = array('default');
+               }
+
+               $localLanguage = array();
+               foreach ($languages as $language) {
+                       $tempLL = \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile($fileRef, $language, $this->renderCharset);
+                       $localLanguage['default'] = $tempLL['default'];
+                       if (!isset($localLanguage[$this->lang])) {
+                               $localLanguage[$this->lang] = $localLanguage['default'];
+                       }
+                       if ($this->lang !== 'default' && isset($tempLL[$language])) {
+                               // Merge current language labels onto labels from previous language
+                               // This way we have a label with fall back applied
+                               $localLanguage[$this->lang] = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($localLanguage[$this->lang], $tempLL[$language], FALSE, FALSE);
+                       }
+               }
+
+               return $localLanguage;
        }
 
        /**
@@ -4628,6 +4660,20 @@ if (version == "n3") {
                // Setting language key and split index:
                $this->lang = $this->config['config']['language'] ? $this->config['config']['language'] : 'default';
                $this->getPageRenderer()->setLanguage($this->lang);
+
+               // Finding the requested language in this list based
+               // on the $lang key being inputted to this function.
+               /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
+               $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
+
+               // Language is found. Configure it:
+               if (in_array($this->lang, $locales->getLocales())) {
+                       $this->languageDependencies[] = $this->lang;
+                       foreach ($locales->getLocaleDependencies($this->lang) as $language) {
+                               $this->languageDependencies[] = $language;
+                       }
+               }
+
                // Setting charsets:
                $this->renderCharset = $this->csConvObj->parse_charset($this->config['config']['renderCharset'] ? $this->config['config']['renderCharset'] : 'utf-8');
                // Rendering charset of HTML page.