update for i18n set cookie by server-side.

This commit is contained in:
kunw 2016-06-29 20:47:32 +08:00
parent 90e025febe
commit dbb35067a6

View File

@ -55,16 +55,23 @@ func (b *BaseController) Prepare() {
b.SetSession("Lang", lang)
lang = sessionLang.(string)
} else {
lang = defaultLang
al := b.Ctx.Request.Header.Get("Accept-Language")
if len(al) > 4 {
al = al[:5] // Only compare first 5 letters.
if i18n.IsExist(al) {
lang = al
}
}
}
}
b.SetSession("Lang", lang)
if _, exist := supportLanguages[lang]; !exist { //Check if support the request language.
lang = defaultLang //Set default language if not supported.
}
b.Ctx.SetCookie("language", lang, 0, "/")
b.SetSession("Lang", lang)
curLang := langType{
Lang: lang,
}