aboutsummaryrefslogtreecommitdiff
path: root/kcore/template.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 08:38:40 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 08:38:40 +0200
commita9927763f43d59c418b264790ccee59defe8ca29 (patch)
tree5dfc4f1f1f29d1ef1cbca3406bf57d1667b93f76 /kcore/template.go
parented23d402fec268e163ec895748f43e3254ba3dfd (diff)
refactor: Rename packages for clarityv0.3.0
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),
+ }
+}