File tree 1 file changed +4
-6
lines changed
1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -15,24 +15,22 @@ import (
15
15
16
16
// Locale handle locale
17
17
func Locale (resp http.ResponseWriter , req * http.Request ) translation.Locale {
18
- hasCookie := false
19
-
20
18
// 1. Check URL arguments.
21
19
lang := req .URL .Query ().Get ("lang" )
20
+ var changeLang = lang != ""
22
21
23
22
// 2. Get language information from cookies.
24
23
if len (lang ) == 0 {
25
24
ck , _ := req .Cookie ("lang" )
26
25
if ck != nil {
27
26
lang = ck .Value
28
- hasCookie = true
29
27
}
30
28
}
31
29
32
30
// Check again in case someone modify by purpose.
33
31
if lang != "" && ! i18n .IsExist (lang ) {
34
32
lang = ""
35
- hasCookie = false
33
+ changeLang = false
36
34
}
37
35
38
36
// 3. Get language information from 'Accept-Language'.
@@ -43,8 +41,8 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
43
41
lang = tag .String ()
44
42
}
45
43
46
- if ! hasCookie {
47
- req . AddCookie ( NewCookie ( "lang" , lang , 1 << 31 - 1 ) )
44
+ if changeLang {
45
+ SetCookie ( resp , "lang" , lang , 1 << 31 - 1 )
48
46
}
49
47
50
48
return translation .NewLocale (lang )
You can’t perform that action at this time.
0 commit comments