mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
优化写法
This commit is contained in:
@@ -110,18 +110,20 @@ class Lang
|
||||
public static function detect()
|
||||
{
|
||||
// 自动侦测设置获取语言选择
|
||||
if (isset($_GET[Config::get('lang_detect_var')])) {
|
||||
$langCookieVar = Config::get('lang_cookie_var');
|
||||
$langDetectVar = Config::get('lang_detect_var');
|
||||
if (isset($_GET[$langDetectVar])) {
|
||||
// url中设置了语言变量
|
||||
$langSet = strtolower($_GET[Config::get('lang_detect_var')]);
|
||||
\think\Cookie::set(Config::get('lang_cookie_var'), $langSet, 3600);
|
||||
} elseif (\think\Cookie::get(Config::get('lang_cookie_var'))) {
|
||||
$langSet = strtolower($_GET[$langDetectVar]);
|
||||
\think\Cookie::set($langCookieVar, $langSet, 3600);
|
||||
} elseif (\think\Cookie::get($langCookieVar)) {
|
||||
// 获取上次用户的选择
|
||||
$langSet = strtolower(\think\Cookie::get(Config::get('lang_cookie_var')));
|
||||
$langSet = strtolower(\think\Cookie::get($langCookieVar));
|
||||
} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
// 自动侦测浏览器语言
|
||||
preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
|
||||
$langSet = strtolower($matches[1]);
|
||||
\think\Cookie::set(Config::get('lang_cookie_var'), $langSet, 3600);
|
||||
\think\Cookie::set($langCookieVar, $langSet, 3600);
|
||||
}
|
||||
if (in_array($langSet, \think\Config::get('lang_list'))) {
|
||||
// 合法的语言
|
||||
|
||||
Reference in New Issue
Block a user