mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
Merge pull request #304 from forLing/feature-i18n_cookie_set
增加方法-多语言-设置多语言cookie过期时间
This commit is contained in:
@@ -25,6 +25,8 @@ class Lang
|
|||||||
protected static $langDetectVar = 'lang';
|
protected static $langDetectVar = 'lang';
|
||||||
// 语言Cookie变量
|
// 语言Cookie变量
|
||||||
protected static $langCookieVar = 'think_var';
|
protected static $langCookieVar = 'think_var';
|
||||||
|
// 语言Cookie的过期时间
|
||||||
|
protected static $langCookieExpire = 3600;
|
||||||
// 允许语言列表
|
// 允许语言列表
|
||||||
protected static $allowLangList = [];
|
protected static $allowLangList = [];
|
||||||
|
|
||||||
@@ -155,7 +157,7 @@ class Lang
|
|||||||
if (isset($_GET[self::$langDetectVar])) {
|
if (isset($_GET[self::$langDetectVar])) {
|
||||||
// url中设置了语言变量
|
// url中设置了语言变量
|
||||||
$langSet = strtolower($_GET[self::$langDetectVar]);
|
$langSet = strtolower($_GET[self::$langDetectVar]);
|
||||||
Cookie::set(self::$langCookieVar, $langSet, 3600);
|
Cookie::set(self::$langCookieVar, $langSet, self::$langCookieExpire);
|
||||||
} elseif (Cookie::get(self::$langCookieVar)) {
|
} elseif (Cookie::get(self::$langCookieVar)) {
|
||||||
// 获取上次用户的选择
|
// 获取上次用户的选择
|
||||||
$langSet = strtolower(Cookie::get(self::$langCookieVar));
|
$langSet = strtolower(Cookie::get(self::$langCookieVar));
|
||||||
@@ -163,7 +165,7 @@ class Lang
|
|||||||
// 自动侦测浏览器语言
|
// 自动侦测浏览器语言
|
||||||
preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
|
preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
|
||||||
$langSet = strtolower($matches[1]);
|
$langSet = strtolower($matches[1]);
|
||||||
Cookie::set(self::$langCookieVar, $langSet, 3600);
|
Cookie::set(self::$langCookieVar, $langSet, self::$langCookieExpire);
|
||||||
}
|
}
|
||||||
if (empty(self::$allowLangList) || in_array($langSet, self::$allowLangList)) {
|
if (empty(self::$allowLangList) || in_array($langSet, self::$allowLangList)) {
|
||||||
// 合法的语言
|
// 合法的语言
|
||||||
@@ -195,6 +197,16 @@ class Lang
|
|||||||
self::$langCookieVar = $var;
|
self::$langCookieVar = $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置语言的cookie的过期时间
|
||||||
|
* @param string $expire 过期时间
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setLangCookieExpire($expire)
|
||||||
|
{
|
||||||
|
self::$langCookieExpire = $expire;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置允许的语言列表
|
* 设置允许的语言列表
|
||||||
* @param array $list 语言列表
|
* @param array $list 语言列表
|
||||||
|
|||||||
Reference in New Issue
Block a user