diff options
Diffstat (limited to 'http/handler')
-rw-r--r-- | http/handler/context.go | 9 | ||||
-rw-r--r-- | http/handler/handler.go | 5 |
2 files changed, 9 insertions, 5 deletions
diff --git a/http/handler/context.go b/http/handler/context.go index a04a816..35eb1ea 100644 --- a/http/handler/context.go +++ b/http/handler/context.go @@ -80,8 +80,12 @@ func (c *Context) LoggedUser() *model.User { // UserLanguage get the locale used by the current logged user. func (c *Context) UserLanguage() string { - user := c.LoggedUser() - return user.Language + if c.IsAuthenticated() { + user := c.LoggedUser() + return user.Language + } + + return c.getContextStringValue(middleware.UserLanguageContextKey) } // Translate translates a message in the current language. @@ -145,7 +149,6 @@ func (c *Context) getContextStringValue(key *middleware.ContextKey) string { return v.(string) } - logger.Error("[Core:Context] Missing key: %s", key) return "" } diff --git a/http/handler/handler.go b/http/handler/handler.go index 3dd1d1b..882e0bd 100644 --- a/http/handler/handler.go +++ b/http/handler/handler.go @@ -46,9 +46,10 @@ func (h *Handler) Use(f ControllerFunc) http.Handler { ctx := NewContext(r, h.store, h.router, h.translator) request := NewRequest(r) response := NewResponse(w, r, h.template) + language := ctx.UserLanguage() - if ctx.IsAuthenticated() { - h.template.SetLanguage(ctx.UserLanguage()) + if language != "" { + h.template.SetLanguage(language) } else { h.template.SetLanguage("en_US") } |