update
This commit is contained in:
@ -58,9 +58,13 @@ func queryBool(c *gin.Context, key string, def bool) bool {
|
||||
return v == "1" || v == "true"
|
||||
}
|
||||
|
||||
// parseLocale 解析请求语言,优先级:?locale=cn|en > Accept-Language > 默认 en。
|
||||
// 与前端 i18n/config.ts 的 LOCALES=['en','cn']、DEFAULT_LOCALE='en' 保持一致。
|
||||
// parseLocale 解析请求语言,优先级:X-Locale 头 > ?locale=cn|en > Accept-Language > 默认 en。
|
||||
// 与前端 i18n 的 LOCALES=['en','cn']、DEFAULT_LOCALE='en' 保持一致。
|
||||
// X-Locale 由前端统一经请求头透传「当前页面语言」,显式且不受浏览器语言设置干扰。
|
||||
func parseLocale(c *gin.Context) string {
|
||||
if l := strings.ToLower(strings.TrimSpace(c.GetHeader("X-Locale"))); l == "cn" || l == "en" {
|
||||
return l
|
||||
}
|
||||
if l := strings.ToLower(strings.TrimSpace(c.Query("locale"))); l == "cn" || l == "en" {
|
||||
return l
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user