- Go 后端 handler 错误消息统一中文化(middleware/repos/generate/review/settings) - 前端 JS 加载和错误消息中文化(diff-viewer.js, graph.js) - 模板页面错误 fallback 和静态文本中文化(index/generate/review/base) - 消除中英文混杂,提升中文用户体验
This commit is contained in:
@@ -22,7 +22,7 @@ func NewGenerateHandler(db *sql.DB) *GenerateHandler {
|
||||
func (h *GenerateHandler) Generate(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
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (h *GenerateHandler) Generate(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 {
|
||||
@@ -46,7 +46,7 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
Head string `json:"head" binding:"required"`
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ func (h *GenerateHandler) Generate(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()
|
||||
@@ -85,12 +85,12 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
// Save analysis to DB with user_id
|
||||
resultJSON, err := json.Marshal(pr)
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "marshal result: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "序列化结果失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if _, err := h.db.Exec(`INSERT INTO analyses (user_id, repo_id, type, base_ref, head_ref, result) VALUES (?, ?, 'pr_description', ?, ?, ?)`,
|
||||
user.ID, id, req.Base, req.Head, string(resultJSON)); err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "save analysis: " + err.Error()})
|
||||
sendEvent("error", map[string]interface{}{"message": "保存分析结果失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user