File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -15,24 +15,22 @@ import (
1515
1616// Locale handle locale
1717func Locale (resp http.ResponseWriter , req * http.Request ) translation.Locale {
18- hasCookie := false
19-
2018 // 1. Check URL arguments.
2119 lang := req .URL .Query ().Get ("lang" )
20+ var changeLang = lang != ""
2221
2322 // 2. Get language information from cookies.
2423 if len (lang ) == 0 {
2524 ck , _ := req .Cookie ("lang" )
2625 if ck != nil {
2726 lang = ck .Value
28- hasCookie = true
2927 }
3028 }
3129
3230 // Check again in case someone modify by purpose.
3331 if lang != "" && ! i18n .IsExist (lang ) {
3432 lang = ""
35- hasCookie = false
33+ changeLang = false
3634 }
3735
3836 // 3. Get language information from 'Accept-Language'.
@@ -43,8 +41,8 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
4341 lang = tag .String ()
4442 }
4543
46- if ! hasCookie {
47- req . AddCookie ( NewCookie ( "lang" , lang , 1 << 31 - 1 ) )
44+ if changeLang {
45+ SetCookie ( resp , "lang" , lang , 1 << 31 - 1 )
4846 }
4947
5048 return translation .NewLocale (lang )
You can’t perform that action at this time.
0 commit comments