package functions
import (
"html/template"
"strconv"
"strings"
"time"
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/config"
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
)
type ServiceProvider interface {
ConfigService() *config.Service
}
func Now() time.Time {
return time.Now()
}
func NoEscape(str string) template.HTML {
return template.HTML(str)
}
func Concat(parts ...string) string {
return strings.Join(parts, "")
}
func GridSep(i, l int) bool {
i++
return i%3 == 0 && i != l
}
func Version(sp ServiceProvider) func() string {
return func() string {
return strconv.FormatUint(uint64(sp.ConfigService().StaticVersion()), 10)
}
}
func Trans(lang i18n.Language, key string) string {
return i18n.T(lang, key)
}
func Link(lang i18n.Language, link string) string {
if lang == i18n.DefaultLanguage() {
return link
}
if link == "/" {
return "/" + string(lang)
}
return "/" + string(lang) + link
}