summaryrefslogtreecommitdiff
path: root/core/template.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 07:20:10 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 07:20:29 +0200
commit18476c6cba2d5d2bb3ecf3ad136dacbf41d0360e (patch)
treea7a958ff7a4bf14ed7f7ee3ffd9c84b7592facbd /core/template.go
feat: Extract from other repo
Diffstat (limited to 'core/template.go')
-rw-r--r--core/template.go33
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),
+ }
+}