From 557a4d23c7f627175db652d0dd4ca78527da4c9f Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 25 Jan 2024 11:15:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=B7=E6=B1=82=E8=A7=A3=E6=9E=90lang?= =?UTF-8?q?uage=E8=AF=AD=E8=A8=80=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/utils/ctx/ctx.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/framework/utils/ctx/ctx.go b/src/framework/utils/ctx/ctx.go index b2ba35d5..b005e13e 100644 --- a/src/framework/utils/ctx/ctx.go +++ b/src/framework/utils/ctx/ctx.go @@ -104,19 +104,22 @@ func UaOsBrowser(c *gin.Context) (string, string) { // AcceptLanguage 解析客户端接收语言 zh:中文 en: 英文 func AcceptLanguage(c *gin.Context) string { preferredLanguage := language.English - acceptLanguage := "en_US" + // Query请求查询 - if v, ok := c.GetQuery("lang"); ok && v != "" { - acceptLanguage = v + if v, ok := c.GetQuery("language"); ok && v != "" { + tags, _, _ := language.ParseAcceptLanguage(v) + if len(tags) > 0 { + preferredLanguage = tags[0] + } } // Header请求头 if v := c.GetHeader("Accept-Language"); v != "" { - acceptLanguage = v - } - tags, _, _ := language.ParseAcceptLanguage(acceptLanguage) - if len(tags) > 0 { - preferredLanguage = tags[0] + tags, _, _ := language.ParseAcceptLanguage(v) + if len(tags) > 0 { + preferredLanguage = tags[0] + } } + // 只取前缀 lang := preferredLanguage.String() arr := strings.Split(lang, "-")