mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +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")
|
||||
},
|
||||
|
||||
@@ -2,12 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/naiba/nezha/cmd/dashboard/controller"
|
||||
"github.com/naiba/nezha/cmd/dashboard/rpc"
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/service/singleton"
|
||||
"github.com/ory/graceful"
|
||||
"log"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -15,6 +16,7 @@ func init() {
|
||||
singleton.Init()
|
||||
singleton.InitConfigFromPath("data/config.yaml")
|
||||
singleton.InitDBFromPath("data/sqlite.db")
|
||||
singleton.InitLocalizer()
|
||||
initSystem()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user