feat(api): localize console pages and api error messages
The language comes from the user setting, then the lang cookie, then Accept-Language, falling back to English. Errors keep a stable code and carry a translated message. Closes #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
dde7b890b8
commit
70190446ff
12 files changed
+698
-211
No files matched your search
@@ -10,15 +10,15 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
||||
)
|
||||
|
||||
func (s *Server) RegisterPages(r gin.IRouter) {
|
||||
func (s *Server) registerPages(r gin.IRouter) {
|
||||
r.GET("/login", s.loginPage)
|
||||
r.GET("/signup", s.signupPage)
|
||||
r.GET("/", s.page("Übersicht", web.Dashboard))
|
||||
r.GET("/settings/security", s.page("Sicherheit", web.Security))
|
||||
r.GET("/", s.page("console.monitors.title", web.Dashboard))
|
||||
r.GET("/settings/security", s.page("security.title", web.Security))
|
||||
}
|
||||
|
||||
func pageFor(c *gin.Context, title string) web.Page {
|
||||
p := web.Page{Title: title}
|
||||
func (s *Server) pageFor(c *gin.Context, titleID string) web.Page {
|
||||
p := web.Page{TitleID: titleID, Languages: s.catalog.Supported()}
|
||||
if sess := auth.Current(c); sess != nil {
|
||||
p.CSRF = sess.CSRF
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func (s *Server) loginPage(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
web.Render(c, http.StatusOK, web.Login(pageFor(c, "Anmelden"), allowed))
|
||||
web.Render(c, http.StatusOK, web.Login(s.pageFor(c, "auth.login.title"), allowed))
|
||||
}
|
||||
|
||||
func (s *Server) signupPage(c *gin.Context) {
|
||||
@@ -48,10 +48,10 @@ func (s *Server) signupPage(c *gin.Context) {
|
||||
c.Redirect(http.StatusSeeOther, "/login")
|
||||
return
|
||||
}
|
||||
web.Render(c, http.StatusOK, web.Signup(pageFor(c, "Konto anlegen")))
|
||||
web.Render(c, http.StatusOK, web.Signup(s.pageFor(c, "auth.signup.title")))
|
||||
}
|
||||
|
||||
func (s *Server) page(title string, view func(web.Page, web.Me) templ.Component) gin.HandlerFunc {
|
||||
func (s *Server) page(titleID string, view func(web.Page, web.Me) templ.Component) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
sess := auth.Current(c)
|
||||
if sess == nil {
|
||||
@@ -63,7 +63,7 @@ func (s *Server) page(title string, view func(web.Page, web.Me) templ.Component)
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
web.Render(c, http.StatusOK, view(pageFor(c, title), toWebMe(me)))
|
||||
web.Render(c, http.StatusOK, view(s.pageFor(c, titleID), toWebMe(me)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user