aboutsummaryrefslogtreecommitdiff
path: root/kcore/template.go
diff options
context:
space:
mode:
Diffstat (limited to 'kcore/template.go')
-rw-r--r--kcore/template.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/kcore/template.go b/kcore/template.go
new file mode 100644
index 0000000..33b2f5a
--- /dev/null
+++ b/kcore/template.go
@@ -0,0 +1,33 @@
+package kcore
+
+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 Login[U any] struct {
+ Ok bool
+ User U
+ Tr Tr
+}
+
+func LoginFromUser[U WithLanguage](user U, ok bool) Login[U] {
+ return Login[U]{
+ Ok: ok,
+ User: user,
+ Tr: GetTr(user),
+ }
+}