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'));
+ }
}
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'));
- }
}
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.
*
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'.
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;
}