diff --git a/server/common/app.go b/server/common/app.go index 95e4cba0..d1dc6abe 100644 --- a/server/common/app.go +++ b/server/common/app.go @@ -11,4 +11,5 @@ type App struct { Share Share Context context.Context Authorization string + Languages []string } diff --git a/server/middleware/session.go b/server/middleware/session.go index 511e9e7c..c682ac8b 100644 --- a/server/middleware/session.go +++ b/server/middleware/session.go @@ -71,6 +71,8 @@ func SessionStart(fn HandlerFunc) HandlerFunc { SendErrorResult(res, err) return } + ctx.Languages = _extractLanguages(req) + fn(ctx, res, req) }) } @@ -327,3 +329,15 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) { func _extractBackend(req *http.Request, ctx *App) (IBackend, error) { return model.NewBackend(ctx, ctx.Session) } + +func _extractLanguages(req *http.Request) []string { + var lng = []string{} + for _, lngs := range strings.Split(req.Header.Get("Accept-Language"), ",") { + chunks := strings.Split(lngs, ";") + if len(chunks) == 0 { + continue + } + lng = append(lng, chunks[0]) + } + return lng +}