[BUGFIX] Locales dependency is not taken into account
authorXavier Perseguers <xavier@typo3.org>
Thu, 1 Sep 2011 12:21:18 +0000 (14:21 +0200)
committerAndreas Wolf <andreas.wolf@ikt-werk.de>
Thu, 8 Sep 2011 12:47:13 +0000 (14:47 +0200)
Localization methods do not take global or user-defined locales
dependencies into account when retrieving a label for a given language.
Instead, they always fall back to default (English) if the requested
language key was not found.

Change-Id: Icb2789e9ad3c56b65d098fe136d898954e39a51c
Fixes: #29386
Releases: 4.6
Reviewed-on: http://review.typo3.org/4718
Reviewed-by: Xavier Perseguers
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
typo3/sysext/lang/lang.php

index 53dd2e5..2b83b8f 100755 (executable)
@@ -117,6 +117,14 @@ class language {
        public $parserFactory;
 
        /**
+        * List of language dependencies for actual language. This is used for local variants of a language
+        * that depend on their "main" language, like Brazilian Portugese or Canadian French.
+        *
+        * @var array
+        */
+       protected $languageDependencies = array();
+
+       /**
         * Initializes the backend language.
         * This is for example done in typo3/template.php with lines like these:
         *
@@ -150,6 +158,11 @@ class language {
                                        // The charset if different from the default.
                                $this->charSet = $this->charSetArray[$this->lang];
                        }
+
+                       $this->languageDependencies[] = $this->lang;
+                       foreach ($locales->getLocaleDependencies($this->lang) as $language) {
+                               $this->languageDependencies[] = $language;
+                       }
                }
 
                if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lang']['debug']) {
@@ -522,7 +535,27 @@ class language {
         * @access      private
         */
        protected function readLLfile($fileRef) {
-               return t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet);
+               if ($this->lang !== 'default') {
+                       $languages = array_reverse($this->languageDependencies);
+               } else {
+                       $languages = array('default');
+               }
+
+               $localLanguage = array();
+               foreach ($languages as $language) {
+                       $tempLL = t3lib_div::readLLfile($fileRef, $language, $this->charSet);
+                       $localLanguage['default'] = $tempLL['default'];
+                       if (!isset($localLanguage[$this->lang])) {
+                               $localLanguage[$this->lang] = $localLanguage['default'];
+                       }
+                       if ($this->lang !== 'default') {
+                                       // Merge current language labels onto labels from previous language
+                                       // This way we have a labels with fall back applied
+                               $localLanguage[$this->lang] = t3lib_div::array_merge_recursive_overrule($localLanguage[$this->lang], $tempLL[$language], FALSE, FALSE);
+                       }
+               }
+
+               return $localLanguage;
        }
 
        /**