/** * 设置国际化管理类 * @param \tfc\util\Language $language * @return void */ public static function setLanguage(Language $language = null) { if ($language === null) { $type = Ap::getLanguageType(); $baseDir = DIR_APP_LANGUAGES; $language = Language::getInstance($type, $baseDir); } self::$_language = $language; }
/** * 通过键名获取语言内容 * @param string $string * @param boolean $jsSafe * @param boolean $interpretBackSlashes * @return string */ public static function _($string, $jsSafe = false, $interpretBackSlashes = true) { static $language = null; if ($language === null) { $type = Ap::getLanguageType(); $baseDir = substr(dirname(__FILE__), 0, -8) . DS . 'languages'; $language = Language::getInstance($type, $baseDir); } return $language->_($string, $jsSafe, $interpretBackSlashes); }
/** * 将常用数据设置到模板变量中 * @return void */ public function assignSystem() { $viw = Mvc::getView(); $viw->assign('app', APP_NAME); $viw->assign('module', Mvc::$module); $viw->assign('controller', Mvc::$controller); $viw->assign('action', Mvc::$action); $viw->assign('sidebar', Mvc::$module . '/' . Mvc::$controller . '_sidebar'); $viw->assign('log_id', Log::getId()); $viw->assign('language', Ap::getLanguageType()); if (($wfBackTrace = Registry::get('warning_backtrace')) !== null) { $viw->assign('warning_backtrace', $wfBackTrace); } }
/** * 初始化输出的语言种类 * @return void * @throws InvalidArgumentException 如果不是可支持的输出语种,抛出异常 */ protected function _initLanguageType() { // 验证配置中的当前输出语种是否合法 try { $languageType = trim(Cfg::getApp('language')); Ap::setLanguageType($languageType); } catch (ErrorException $e) { } if (!in_array(Ap::getLanguageType(), $this->_languageTypes)) { throw new InvalidArgumentException('BaseAction is unable to determine the language of the config.'); } // 从RGP中获取‘ol’的值(output language type),并验证是否合法 // 以RGP中指定的输出语种为主 $languageType = Ap::getRequest()->getTrim('ol'); if ($languageType !== '') { if (in_array($languageType, $this->_languageTypes)) { Ap::setLanguageType($languageType); } else { throw new InvalidArgumentException('BaseAction is unable to determine the language of the request.'); } } }
/** * 将常用数据设置到模板变量中 * @return void */ public function assignSystem() { $viw = Mvc::getView(); $viw->assign('app', APP_NAME); $viw->assign('module', Mvc::$module); $viw->assign('controller', Mvc::$controller); $viw->assign('action', Mvc::$action); $viw->assign('sidebar', Mvc::$module . '/' . Mvc::$action . '_sidebar'); $viw->assign('log_id', Log::getId()); $viw->assign('language', Ap::getLanguageType()); $viw->assign('urlHelper', UrlHelper::getInstance()); $viw->assign('site_name', Options::getSiteName()); if (!isset($viw->meta_title)) { $viw->assign('meta_title', Options::getMetaTitle()); } if (!isset($viw->meta_keywords)) { $viw->assign('meta_keywords', Options::getMetaKeywords()); } if (!isset($viw->meta_description)) { $viw->assign('meta_description', Options::getMetaDescription()); } $viw->assign('powerby', Options::getPowerby()); $viw->assign('stat_code', Options::getStatCode()); if (($wfBackTrace = Registry::get('warning_backtrace')) !== null) { $viw->assign('warning_backtrace', $wfBackTrace); } }