diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-01-27 22:20:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-27 16:20:42 +0200 |
commit | 669ff8e9b1c15d24dd30852588c2dbb3d82e0cd9 (patch) | |
tree | a7ed4886fdc9da449547e616cb41a75e3ff3ecae | |
parent | af7f71207c3e9f62a873e3d4a0b57cdbfe121bb1 (diff) | |
download | gitea-669ff8e9b1c15d24dd30852588c2dbb3d82e0cd9.tar.gz gitea-669ff8e9b1c15d24dd30852588c2dbb3d82e0cd9.zip |
Fix switch language (#14484)
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
-rw-r--r-- | modules/middlewares/locale.go | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/modules/middlewares/locale.go b/modules/middlewares/locale.go index 7cfba81bda..21980ad486 100644 --- a/modules/middlewares/locale.go +++ b/modules/middlewares/locale.go @@ -15,24 +15,22 @@ import ( // Locale handle locale func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { - hasCookie := false - // 1. Check URL arguments. lang := req.URL.Query().Get("lang") + var changeLang = lang != "" // 2. Get language information from cookies. if len(lang) == 0 { ck, _ := req.Cookie("lang") if ck != nil { lang = ck.Value - hasCookie = true } } // Check again in case someone modify by purpose. if lang != "" && !i18n.IsExist(lang) { lang = "" - hasCookie = false + changeLang = false } // 3. Get language information from 'Accept-Language'. @@ -43,8 +41,8 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale { lang = tag.String() } - if !hasCookie { - req.AddCookie(NewCookie("lang", lang, 1<<31-1)) + if changeLang { + SetCookie(resp, "lang", lang, 1<<31-1) } return translation.NewLocale(lang) |