mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 20:50:06 +00:00
🌐 localization [skip ci]
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
"github.com/gin-contrib/pprof"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
|
||||
"github.com/naiba/nezha/pkg/mygin"
|
||||
"github.com/naiba/nezha/service/singleton"
|
||||
@@ -26,6 +27,18 @@ func ServeWeb(port uint) *http.Server {
|
||||
}
|
||||
r.Use(mygin.RecordPath)
|
||||
r.SetFuncMap(template.FuncMap{
|
||||
"tr": func(id string, dataAndCount ...interface{}) string {
|
||||
conf := i18n.LocalizeConfig{
|
||||
MessageID: id,
|
||||
}
|
||||
if len(dataAndCount) > 1 {
|
||||
conf.TemplateData = dataAndCount[1]
|
||||
}
|
||||
if len(dataAndCount) > 2 {
|
||||
conf.PluralCount = dataAndCount[2]
|
||||
}
|
||||
return singleton.Localizer.MustLocalize(&conf)
|
||||
},
|
||||
"tf": func(t time.Time) string {
|
||||
return t.In(singleton.Loc).Format("2006年1月2号 15:04:05")
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user