From c352823e52cafb2f7b4ea39f5f63d69ecb6eba5f Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 22 Sep 2011 21:34:50 +0200 Subject: [PATCH] Fixed some issues in the language system --- .../lib/data/language/Language.class.php | 12 +++++++ .../lib/data/language/SetupLanguage.class.php | 12 ------- .../install/files/lib/system/WCF.class.php | 3 +- .../system/language/LanguageFactory.class.php | 34 +++++++++---------- .../LangPrefilterTemplatePlugin.class.php | 4 ++- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/wcfsetup/install/files/lib/data/language/Language.class.php b/wcfsetup/install/files/lib/data/language/Language.class.php index 9873f7b2d8..6bd3ef2666 100644 --- a/wcfsetup/install/files/lib/data/language/Language.class.php +++ b/wcfsetup/install/files/lib/data/language/Language.class.php @@ -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')); + } } diff --git a/wcfsetup/install/files/lib/data/language/SetupLanguage.class.php b/wcfsetup/install/files/lib/data/language/SetupLanguage.class.php index 330e081b7b..afaf562f08 100644 --- a/wcfsetup/install/files/lib/data/language/SetupLanguage.class.php +++ b/wcfsetup/install/files/lib/data/language/SetupLanguage.class.php @@ -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')); - } } diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 9e90976ffe..e673a65eaa 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php b/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php index 1beae1e20f..2ed6c297fa 100644 --- a/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php +++ b/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php @@ -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'. diff --git a/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php index 56366e0396..c5e8c72c6a 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php @@ -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; } -- 2.20.1