From 9042aa781188cbf8d81344b16592e21ad6127ddc Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Fri, 8 Apr 2022 19:11:37 -0600 Subject: [PATCH] Adding helper functions for translations --- core/local.go | 7 ++++++- core/template.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/local.go b/core/local.go index 8dd3bdf..deee80b 100644 --- a/core/local.go +++ b/core/local.go @@ -8,7 +8,7 @@ import ( "hg.code.netlandish.com/~netlandish/gobwebs/server" ) -var sessionLanguage string = "sess_language" +var sessionLanguage string = "_language" // SetLang sets language in the users session func SetLang(c echo.Context, lang string) error { @@ -28,6 +28,11 @@ func GetLang(c echo.Context) string { return lang } +// GetDefaultLang returns the server set DefaultLang +func GetDefaultLang() string { + return localizer.DefaultLang +} + // GetLocalizer fetches a Localizer for given language using the Gatalog // (gobwebs specific) language catalog func GetLocalizer(lang string) (*localizer.Localizer, bool) { diff --git a/core/template.go b/core/template.go index 9c0fe90..9f93526 100644 --- a/core/template.go +++ b/core/template.go @@ -7,6 +7,13 @@ import ( "hg.code.netlandish.com/~netlandish/gobwebs/server" ) +// AddContext will add the echo.Context into the template namespace +func AddContext(c echo.Context) gobwebs.Map { + return gobwebs.Map{ + "context": c, + } +} + // LoadMessages loads all session flash messages into template data // context under the variable name `messages` func LoadMessages(c echo.Context) gobwebs.Map { -- 2.45.2