diff options
Diffstat (limited to 'core/template.go')
| -rw-r--r-- | core/template.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/template.go b/core/template.go new file mode 100644 index 0000000..3a6833a --- /dev/null +++ b/core/template.go @@ -0,0 +1,33 @@ +package core + +import ( + "github.com/kataras/i18n" +) + +type Tr = func(format string, args ...any) string + +type WithLanguage interface { + Language() string +} + +func GetTr(wl WithLanguage) Tr { + lang := "en-GB" + if wl != nil { + lang = wl.Language() + } + return func(format string, args ...any) string { return i18n.Tr(lang, format, args...) } +} + +type LoginContext[U any] struct { + IsLoggedIn bool + User U + Tr Tr +} + +func GetLoginContext[U WithLanguage](user U, ok bool) LoginContext[U] { + return LoginContext[U]{ + IsLoggedIn: ok, + User: user, + Tr: GetTr(user), + } +} |
