From 8b0078d9367d1e4845eb09a6e6a59d741585336c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 13 Jun 2016 17:05:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BLang=E7=B1=BB=E7=9A=84detect?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E8=BF=94=E5=9B=9E=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=20=E5=8F=96=E6=B6=88=20LANG=5FSET=20?= =?UTF-8?q?=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 8 ++++---- library/think/Lang.php | 1 + library/think/Request.php | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 6b911fdb..c25cc92b 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -68,11 +68,11 @@ class App // 开启多语言机制 if ($config['lang_switch_on']) { // 获取当前语言 - defined('LANG_SET') or define('LANG_SET', Lang::range()); + $request->langset(Lang::detect()); // 加载系统语言包 - Lang::load(THINK_PATH . 'lang' . DS . LANG_SET . EXT); + Lang::load(THINK_PATH . 'lang' . DS . $request->langset() . EXT); if (!APP_MULTI_MODULE) { - Lang::load(APP_PATH . 'lang' . DS . LANG_SET . EXT); + Lang::load(APP_PATH . 'lang' . DS . $request->langset() . EXT); } } @@ -349,7 +349,7 @@ class App // 加载当前模块语言包 if ($config['lang_switch_on'] && $module) { - Lang::load($path . 'lang' . DS . LANG_SET . EXT); + Lang::load($path . 'lang' . DS . Request::instance()->langset() . EXT); } } return Config::get(); diff --git a/library/think/Lang.php b/library/think/Lang.php index 2a60fcbf..fe94bf7e 100644 --- a/library/think/Lang.php +++ b/library/think/Lang.php @@ -157,6 +157,7 @@ class Lang // 合法的语言 self::$range = $langSet; } + return self::$range; } /** diff --git a/library/think/Request.php b/library/think/Request.php index d4deb6f2..d10f5ddb 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -71,6 +71,7 @@ class Request protected $module; protected $controller; protected $action; + protected $langset; /** * @var array 请求参数 @@ -968,4 +969,20 @@ class Request return $this->action ?: ''; } } + + /** + * 设置或者获取当前的语言 + * @access public + * @param string $lang 语言名 + * @return string + */ + public function langset($lang = null) + { + if (!is_null($lang)) { + $this->langset = $lang; + return $this; + } else { + return $this->langset ?: ''; + } + } }