i18n: 中文化所有错误消息和用户交互文本
Deploy PR-Helper / deploy (push) Successful in 31s

- Go 后端 handler 错误消息统一中文化(middleware/repos/generate/review/settings)
- 前端 JS 加载和错误消息中文化(diff-viewer.js, graph.js)
- 模板页面错误 fallback 和静态文本中文化(index/generate/review/base)
- 消除中英文混杂,提升中文用户体验
This commit is contained in:
2026-06-21 15:11:20 +08:00
parent a6bd46db34
commit 55bfdf08ce
11 changed files with 66 additions and 66 deletions
+19 -19
View File
@@ -24,7 +24,7 @@ func NewReviewHandler(db *sql.DB) *ReviewHandler {
func (h *ReviewHandler) Review(c *gin.Context) {
user := GetCurrentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
return
}
@@ -34,7 +34,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
var localPath string
err := h.db.QueryRow(`SELECT local_path FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath)
if err == sql.ErrNoRows {
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
c.JSON(http.StatusNotFound, gin.H{"error": "仓库未找到"})
return
}
if err != nil {
@@ -50,7 +50,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
Concurrency *int `json:"concurrency"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "base and head are required"})
c.JSON(http.StatusBadRequest, gin.H{"error": "请选择 Base 和 Head 分支"})
return
}
@@ -91,14 +91,14 @@ func (h *ReviewHandler) Review(c *gin.Context) {
flusher, ok := c.Writer.(http.Flusher)
if !ok {
c.JSON(http.StatusInternalServerError, gin.H{"error": "streaming not supported"})
c.JSON(http.StatusInternalServerError, gin.H{"error": "服务器不支持流式传输"})
return
}
sendEvent := func(event string, data interface{}) {
jsonData, err := json.Marshal(data)
if err != nil {
jsonData = []byte(`{"error":"failed to marshal event data"}`)
jsonData = []byte(`{"error":"序列化事件数据失败"}`)
}
fmt.Fprintf(c.Writer, "event: %s\ndata: %s\n\n", event, jsonData)
flusher.Flush()
@@ -117,18 +117,18 @@ func (h *ReviewHandler) Review(c *gin.Context) {
// Save analysis to DB with user_id
resultJSON, err := json.Marshal(reviewResult)
if err != nil {
sendEvent("error", map[string]interface{}{"message": "marshal result: " + err.Error()})
sendEvent("error", map[string]interface{}{"message": "序列化结果失败: " + err.Error()})
return
}
res, err := h.db.Exec(`INSERT INTO analyses (user_id, repo_id, type, base_ref, head_ref, result) VALUES (?, ?, 'code_review', ?, ?, ?)`,
user.ID, id, req.Base, req.Head, string(resultJSON))
if err != nil {
sendEvent("error", map[string]interface{}{"message": "save analysis: " + err.Error()})
sendEvent("error", map[string]interface{}{"message": "保存分析结果失败: " + err.Error()})
return
}
analysisID, err := res.LastInsertId()
if err != nil {
sendEvent("error", map[string]interface{}{"message": "get analysis id: " + err.Error()})
sendEvent("error", map[string]interface{}{"message": "获取分析记录失败: " + err.Error()})
return
}
sendEvent("analysis_saved", map[string]interface{}{
@@ -140,7 +140,7 @@ func (h *ReviewHandler) Review(c *gin.Context) {
func (h *ReviewHandler) SaveNotes(c *gin.Context) {
user := GetCurrentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
return
}
@@ -151,7 +151,7 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
Content string `json:"content"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id and scope are required"})
c.JSON(http.StatusBadRequest, gin.H{"error": "缺少必要参数"})
return
}
@@ -160,7 +160,7 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
case "overall", "file", "suggestion":
// valid
default:
c.JSON(http.StatusBadRequest, gin.H{"error": "scope must be overall, file, or suggestion"})
c.JSON(http.StatusBadRequest, gin.H{"error": "scope 参数无效"})
return
}
@@ -168,7 +168,7 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
var analysisOwnerID int64
err := h.db.QueryRow(`SELECT user_id FROM analyses WHERE id = ?`, req.AnalysisID).Scan(&analysisOwnerID)
if err == sql.ErrNoRows || analysisOwnerID != user.ID {
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
c.JSON(http.StatusNotFound, gin.H{"error": "分析记录未找到"})
return
}
if err != nil {
@@ -189,19 +189,19 @@ func (h *ReviewHandler) SaveNotes(c *gin.Context) {
func (h *ReviewHandler) GetNotes(c *gin.Context) {
user := GetCurrentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
return
}
analysisIDStr := c.Query("analysis_id")
if analysisIDStr == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id query parameter is required"})
c.JSON(http.StatusBadRequest, gin.H{"error": "缺少 analysis_id 参数"})
return
}
analysisID, err := strconv.ParseInt(analysisIDStr, 10, 64)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid analysis_id"})
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id 无效"})
return
}
@@ -209,7 +209,7 @@ func (h *ReviewHandler) GetNotes(c *gin.Context) {
var analysisOwnerID int64
err = h.db.QueryRow(`SELECT user_id FROM analyses WHERE id = ?`, analysisID).Scan(&analysisOwnerID)
if err == sql.ErrNoRows || analysisOwnerID != user.ID {
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
c.JSON(http.StatusNotFound, gin.H{"error": "分析记录未找到"})
return
}
if err != nil {
@@ -235,7 +235,7 @@ func (h *ReviewHandler) GetNotes(c *gin.Context) {
func (h *ReviewHandler) ListReviews(c *gin.Context) {
user := GetCurrentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
return
}
@@ -278,7 +278,7 @@ func (h *ReviewHandler) ListReviews(c *gin.Context) {
func (h *ReviewHandler) GetReview(c *gin.Context) {
user := GetCurrentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
c.JSON(http.StatusUnauthorized, gin.H{"error": "未登录"})
return
}
@@ -287,7 +287,7 @@ func (h *ReviewHandler) GetReview(c *gin.Context) {
var result, baseRef, headRef, createdAt string
err := h.db.QueryRow(`SELECT result, base_ref, head_ref, created_at FROM analyses WHERE id = ? AND user_id = ? AND type = 'code_review'`, aid, user.ID).Scan(&result, &baseRef, &headRef, &createdAt)
if err == sql.ErrNoRows {
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
c.JSON(http.StatusNotFound, gin.H{"error": "分析记录未找到"})
return
}
if err != nil {