Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

add language

aichy126332ec7c96639
diff --git a/internal/base/server/http.go b/internal/base/server/http.go
index 79d5bb8c..18b75e37 100644
--- a/internal/base/server/http.go
+++ b/internal/base/server/http.go
@@ -4,12 +4,15 @@ import (
"html/template"
"io/fs"
"os"
+ "time"
brotli "github.com/anargu/gin-brotli"
"github.com/answerdev/answer/internal/base/middleware"
+ "github.com/answerdev/answer/internal/base/translator"
"github.com/answerdev/answer/internal/router"
"github.com/answerdev/answer/ui"
"github.com/gin-gonic/gin"
+ "github.com/segmentfault/pacman/i18n"
)
// NewHTTPServer new http server.
@@ -58,6 +61,12 @@ func NewHTTPServer(debug bool,
"templateHTML": func(data string) template.HTML {
return template.HTML(data)
},
+ "translator": func(la i18n.Language, data string) string {
+ return translator.GlobalTrans.Tr(la, data)
+ },
+ "translatorTimeFormat": func(la i18n.Language, timestamp int64) string {
+ return time.Unix(timestamp, 0).Format("2006-01-02 15:04:05")
+ },
})
dev := os.Getenv("DEVCODE")
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index 5cd906f2..6c9a9700 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -274,6 +274,7 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
"userinfo": userinfo,
"scriptPath": tc.scriptPath,
"cssPath": tc.cssPath,
+ "language": handler.GetLang(ctx),
"bio": template.HTML(userinfo.Info.BioHTML),
})
}
diff --git a/ui/template/homepage.html b/ui/template/homepage.html
index c9720b61..f0d6faf8 100644
--- a/ui/template/homepage.html
+++ b/ui/template/homepage.html
@@ -1,6 +1,6 @@
{{template "header" . }}
-
-
+ {{translatorTimeFormat $.language 1669920355}}
+ {{translator $.language "error.object.old_password_verification_failed"}}
<div class="pt-4 mt-2 mb-5 container">
<div class="justify-content-center row">
<div class="col-xxl-7 col-lg-8 col-sm-12">