v1.5.1 增强程序稳定性
This commit is contained in:
@@ -20,35 +20,8 @@ func DefaultMessage(messageCode MessageCode, args ...any) string {
|
||||
}
|
||||
|
||||
func ParseLangFromRequest(req *http.Request) (langCode string) {
|
||||
// parse language from cookie
|
||||
const cookieName = "edgelang"
|
||||
cookie, _ := req.Cookie(cookieName)
|
||||
if cookie != nil && len(cookie.Value) > 0 {
|
||||
// HasLang 内部会转换为小写,但这里也转换以确保一致性
|
||||
langCode = strings.ToLower(cookie.Value)
|
||||
if defaultManager.HasLang(langCode) {
|
||||
return langCode
|
||||
}
|
||||
}
|
||||
|
||||
// parse language from 'Accept-Language'
|
||||
var acceptLanguage = req.Header.Get("Accept-Language")
|
||||
if len(acceptLanguage) > 0 {
|
||||
var pieces = strings.Split(acceptLanguage, ",")
|
||||
for _, lang := range pieces {
|
||||
var index = strings.Index(lang, ";")
|
||||
if index >= 0 {
|
||||
lang = lang[:index]
|
||||
}
|
||||
|
||||
var match = defaultManager.MatchLang(lang)
|
||||
if len(match) > 0 {
|
||||
return match
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defaultManager.DefaultLang()
|
||||
// 强制使用中文
|
||||
return "zh-cn"
|
||||
}
|
||||
|
||||
func ParseLangFromAction(action actions.ActionWrapper) (langCode string) {
|
||||
|
||||
Reference in New Issue
Block a user