Fixed some issues in the language system
authorMarcel Werk <burntime@woltlab.com>
Thu, 22 Sep 2011 19:34:50 +0000 (21:34 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 22 Sep 2011 19:34:50 +0000 (21:34 +0200)
wcfsetup/install/files/lib/data/language/Language.class.php
wcfsetup/install/files/lib/data/language/SetupLanguage.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/language/LanguageFactory.class.php
wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php

index 9873f7b2d80ed9f40d838eb7afb0e77b51e1d65a..6bd3ef2666c50deff16c5217a7c17975e513950c 100644 (file)
@@ -159,4 +159,16 @@ class Language extends DatabaseObject {
                
                return false;
        }
+       
+       /**
+        * Sets the local language.
+        * Recall this function after language changed.
+        *
+        * @param       integer         $languageID
+        */
+       public function setLocale() {
+               // set locale for string comparison, character classification and conversion
+               setlocale(LC_COLLATE, $this->get('wcf.global.locale.unix').'.UTF-8', $this->get('wcf.global.locale.unix'), $this->get('wcf.global.locale.win'));
+               setlocale(LC_CTYPE, $this->get('wcf.global.locale.unix').'.UTF-8', $this->get('wcf.global.locale.unix'), $this->get('wcf.global.locale.win'));
+       }
 }
index 330e081b7bf98395eaa94b1de7ed2905c9a44758..afaf562f08cbd0d1e5735a68a22a023708b7e3ce 100644 (file)
@@ -76,16 +76,4 @@ class SetupLanguage extends Language {
                include_once($filename);
                $this->setLocale();
        }
-       
-       /**
-        * Sets the local language.
-        */
-       private function setLocale() {
-               // set locale for:
-               // - string comparison
-               // - character classification and conversion
-               // - date and time formatting
-               setlocale(LC_COLLATE, $this->get('wcf.global.locale.unix').'.UTF-8', $this->get('wcf.global.locale.unix'), $this->get('wcf.global.locale.win'));
-               setlocale(LC_CTYPE, $this->get('wcf.global.locale.unix').'.UTF-8', $this->get('wcf.global.locale.unix'), $this->get('wcf.global.locale.win'));
-       }
 }
index 9e90976ffe5876481abd1cdc2d97c1f00d79d228..e673a65eaa40d6e014b73b2c1a18efd9026758e4 100644 (file)
@@ -349,7 +349,8 @@ class WCF {
                mb_language('uni');
                
                // get language
-               self::$languageObj = LanguageFactory::getInstance()->getLanguage(self::getSession()->getLanguageID());
+               self::$languageObj = LanguageFactory::getInstance()->getUserLanguage(self::getSession()->getLanguageID());
+               self::$languageObj->setLocale();
        }
        
        /**
index 1beae1e20f153c9c6b3db3178b2d969b7d3324a8..2ed6c297fa1bf2af77757dbca07668d1beabda4b 100644 (file)
@@ -53,19 +53,32 @@ class LanguageFactory extends SingletonFactory {
        public function getLanguage($languageID) {
                if (!isset($this->languages[$languageID])) {
                        $language = new Language($languageID);
-                       
                        if (!$language->languageID) {
-                               $languageID = $this->findPreferredLanguage();
-                               $language = new Language($languageID);
+                               return null;
                        }
                        
                        $this->languages[$language->languageID] = $language;
-                       $this->setLocale($languageID);
                }
                
                return $this->languages[$languageID];
        }
        
+       /**
+        * Gets the preferred language of the current user.
+        *
+        * @param       integer         $languageID
+        * @return      wcf\data\language\Language
+        */
+       public function getUserLanguage($languageID = 0) {
+               if ($languageID) {
+                       $language = $this->getLanguage($languageID);
+                       if ($language !== null) return $language;
+               }
+               
+               $languageID = $this->findPreferredLanguage();
+               return $this->getLanguage($languageID);
+       }
+       
        /**
         * Returns an instance of Language or NULL for a given language code.
         *
@@ -206,19 +219,6 @@ class LanguageFactory extends SingletonFactory {
                CacheHandler::getInstance()->clear(WCF_DIR.'cache/', 'cache.languages.php');
        }
        
-       /**
-        * Sets the local language.
-        * Recall this function after language changed.
-        *
-        * @param       integer         $languageID
-        */
-       protected function setLocale($languageID) {
-               // set locale for string comparison, character classification and
-               // conversion and date and time formatting
-               setlocale(LC_COLLATE, $this->languages[$languageID]->get('wcf.global.locale.unix').'.UTF-8', $this->languages[$languageID]->get('wcf.global.locale.unix'), $this->languages[$languageID]->get('wcf.global.locale.win'));
-               setlocale(LC_CTYPE, $this->languages[$languageID]->get('wcf.global.locale.unix').'.UTF-8', $this->languages[$languageID]->get('wcf.global.locale.unix'), $this->languages[$languageID]->get('wcf.global.locale.win'));
-       }
-       
        /**
         * Removes additional language identifier from given language code.
         * Converts e.g. 'de-informal' to 'de'.
index 56366e0396d2fb8b5f62eb1e05d9a8485ac1f361..c5e8c72c6ab1b8b44db1a5de59f217e090a303d9 100644 (file)
@@ -26,7 +26,9 @@ class LangPrefilterTemplatePlugin implements IPrefilterTemplatePlugin {
        public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler) {
                $ldq = preg_quote($compiler->getLeftDelimiter(), '~');
                $rdq = preg_quote($compiler->getRightDelimiter(), '~');
-               $sourceContent = preg_replace("~{$ldq}lang{$rdq}([\w\.]+){$ldq}/lang{$rdq}~e", 'wcf\system\WCF::getLanguage()->get(\'$1\')', $sourceContent);
+               $sourceContent = preg_replace_callback("~{$ldq}lang{$rdq}([\w\.]+){$ldq}/lang{$rdq}~", function ($match) {
+                       return WCF::getLanguage()->get($match[1]);
+               }, $sourceContent);
 
                return $sourceContent;
        }