fix: fix bug in GetAcceptLanguage() (#1322)

This commit is contained in:
Mr Forest
2022-11-24 20:43:35 +08:00
committed by GitHub
parent 29ec1d2d9c
commit ba9d1e2388
3 changed files with 8 additions and 10 deletions

View File

@ -17,6 +17,7 @@ package controllers
import (
"fmt"
"strconv"
"strings"
"github.com/casdoor/casdoor/conf"
"github.com/casdoor/casdoor/i18n"
@ -56,7 +57,7 @@ func (c *ApiController) T(error string) string {
// GetAcceptLanguage ...
func (c *ApiController) GetAcceptLanguage() string {
lang := c.Ctx.Request.Header.Get("Accept-Language")
if lang == "" {
if lang == "" || !strings.Contains(conf.GetConfigString("languages"), lang[0:2]) {
lang = "en"
}
return lang[0:2]