fix(i18n): use English runtime text and localize system UI

This commit is contained in:
Arthur Koba
2026-10-25 19:44:15 +03:00
parent ada0550571
commit 65a96670d5
289 changed files with 8092 additions and 3426 deletions
+10 -2
View File
@@ -7,6 +7,8 @@ import (
"errors"
"net/http"
"github.com/Rain-kl/Wavelet/pkg/i18n"
"github.com/gin-gonic/gin"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
@@ -31,10 +33,16 @@ func ErrorHandlerMiddleware() gin.HandlerFunc {
var apiErr *APIError
if errors.As(err, &apiErr) {
c.JSON(apiErr.Code, Err(apiErr.Msg))
c.JSON(apiErr.Code, Err(i18n.Translate(Locale(c), apiErr.Msg)))
return
}
c.JSON(http.StatusInternalServerError, Err("内部系统错误"))
c.JSON(http.StatusInternalServerError, Err(i18n.Translate(Locale(c), "Internal system error")))
}
}
// Locale uses the same cookie as the frontend, with Accept-Language for API clients.
func Locale(c *gin.Context) string {
cookie, _ := c.Cookie("NEXT_LOCALE")
return i18n.ResolveLocale(cookie, c.GetHeader("Accept-Language"))
}