From e555accb612e189ab9bdad403958d4e0a6d809ae Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 7 Aug 2024 01:45:48 +0200 Subject: Redirect the user after a language is set --- middleware/i18n.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'middleware') diff --git a/middleware/i18n.go b/middleware/i18n.go index 5e33636..a30a9f6 100644 --- a/middleware/i18n.go +++ b/middleware/i18n.go @@ -28,12 +28,15 @@ func I18n(next http.Handler) http.Handler { } } - used := cmp.Or(p, i18n.DefaultPrinter) - ctx := context.WithValue(r.Context(), PrinterKey, used) + ctx := context.WithValue( + r.Context(), PrinterKey, cmp.Or(p, i18n.DefaultPrinter)) if p == pZero { + http.SetCookie(w, &http.Cookie{ + Name: "redirect", + Value: r.URL.Path, + }) templates.Root(nil, templates.SetLanguage()).Render(ctx, w) - /* TODO: Redirect the user back to where they came from */ } else { next.ServeHTTP(w, r.WithContext(ctx)) } -- cgit v1.2.3