From 55bfdf08ce5f6ead8e67a5dc1452ff2e90890039 Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 21 Jun 2026 15:11:20 +0800 Subject: [PATCH] =?UTF-8?q?i18n:=20=E4=B8=AD=E6=96=87=E5=8C=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E9=94=99=E8=AF=AF=E6=B6=88=E6=81=AF=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BA=A4=E4=BA=92=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Go 后端 handler 错误消息统一中文化(middleware/repos/generate/review/settings) - 前端 JS 加载和错误消息中文化(diff-viewer.js, graph.js) - 模板页面错误 fallback 和静态文本中文化(index/generate/review/base) - 消除中英文混杂,提升中文用户体验 --- handlers/generate.go | 14 ++++++------ handlers/middleware.go | 4 ++-- handlers/repos.go | 40 +++++++++++++++++------------------ handlers/review.go | 38 ++++++++++++++++----------------- handlers/settings.go | 6 +++--- static/js/diff-viewer.js | 14 ++++++------ static/js/graph.js | 6 +++--- templates/layouts/base.html | 2 +- templates/pages/generate.html | 2 +- templates/pages/index.html | 2 +- templates/pages/review.html | 4 ++-- 11 files changed, 66 insertions(+), 66 deletions(-) diff --git a/handlers/generate.go b/handlers/generate.go index 230997c..3b9a2ca 100644 --- a/handlers/generate.go +++ b/handlers/generate.go @@ -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 } } diff --git a/handlers/middleware.go b/handlers/middleware.go index 2576c4b..bfd75ae 100644 --- a/handlers/middleware.go +++ b/handlers/middleware.go @@ -19,7 +19,7 @@ func AuthRequired(db *sql.DB) gin.HandlerFunc { if userID == nil { // Check if it's an API request if len(c.Request.URL.Path) > 4 && c.Request.URL.Path[:5] == "/api/" { - c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"}) + c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "未登录"}) } else { c.Redirect(http.StatusFound, "/login") c.Abort() @@ -36,7 +36,7 @@ func AuthRequired(db *sql.DB) gin.HandlerFunc { session.Clear() session.Save() if len(c.Request.URL.Path) > 4 && c.Request.URL.Path[:5] == "/api/" { - c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"}) + c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "未登录"}) } else { c.Redirect(http.StatusFound, "/login") c.Abort() diff --git a/handlers/repos.go b/handlers/repos.go index 4549dac..e2a0f26 100644 --- a/handlers/repos.go +++ b/handlers/repos.go @@ -26,7 +26,7 @@ func NewReposHandler(db *sql.DB, reposDir string) *ReposHandler { func (h *ReposHandler) ListRepos(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 } @@ -62,7 +62,7 @@ func (h *ReposHandler) ListRepos(c *gin.Context) { func (h *ReposHandler) DeleteRepo(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 } @@ -70,7 +70,7 @@ func (h *ReposHandler) DeleteRepo(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 { @@ -95,7 +95,7 @@ func (h *ReposHandler) DeleteRepo(c *gin.Context) { func (h *ReposHandler) CleanupRepos(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 } @@ -144,7 +144,7 @@ func (h *ReposHandler) CleanupRepos(c *gin.Context) { func (h *ReposHandler) PullRepo(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 } @@ -153,7 +153,7 @@ func (h *ReposHandler) PullRepo(c *gin.Context) { var credential sql.NullString err := h.db.QueryRow(`SELECT local_path, auth_type, credential FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&localPath, &authType, &credential) 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 { @@ -192,7 +192,7 @@ func (h *ReposHandler) PullRepo(c *gin.Context) { func (h *ReposHandler) CloneRepo(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 } @@ -202,7 +202,7 @@ func (h *ReposHandler) CloneRepo(c *gin.Context) { Password string `json:"password"` } if err := c.ShouldBindJSON(&req); err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "url is required"}) + c.JSON(http.StatusBadRequest, gin.H{"error": "请输入仓库地址"}) return } @@ -215,14 +215,14 @@ func (h *ReposHandler) CloneRepo(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() @@ -288,7 +288,7 @@ func (h *ReposHandler) CloneRepo(c *gin.Context) { func (h *ReposHandler) GetGraph(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 } @@ -296,7 +296,7 @@ func (h *ReposHandler) GetGraph(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 { @@ -309,7 +309,7 @@ func (h *ReposHandler) GetGraph(c *gin.Context) { repo, err := services.OpenRepo(localPath) if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": "open repo: " + err.Error()}) + c.JSON(http.StatusInternalServerError, gin.H{"error": "打开仓库失败: " + err.Error()}) return } @@ -333,7 +333,7 @@ func (h *ReposHandler) GetGraph(c *gin.Context) { func (h *ReposHandler) GetDiff(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 } @@ -342,14 +342,14 @@ func (h *ReposHandler) GetDiff(c *gin.Context) { head := c.Query("head") if base == "" || head == "" { - c.JSON(http.StatusBadRequest, gin.H{"error": "base and head query params are required"}) + c.JSON(http.StatusBadRequest, gin.H{"error": "请选择 Base 和 Head 分支"}) return } 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 { @@ -390,7 +390,7 @@ func (h *ReposHandler) GetDiff(c *gin.Context) { func (h *ReposHandler) GetRefs(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 } @@ -398,7 +398,7 @@ func (h *ReposHandler) GetRefs(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 { @@ -425,7 +425,7 @@ func (h *ReposHandler) GetRefs(c *gin.Context) { func (h *ReposHandler) GetCommits(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 } @@ -444,7 +444,7 @@ func (h *ReposHandler) GetCommits(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 { diff --git a/handlers/review.go b/handlers/review.go index 6efd1c6..4597fe5 100644 --- a/handlers/review.go +++ b/handlers/review.go @@ -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 { diff --git a/handlers/settings.go b/handlers/settings.go index 2e9dc03..b2b9b98 100644 --- a/handlers/settings.go +++ b/handlers/settings.go @@ -18,7 +18,7 @@ func NewSettingsHandler(db *sql.DB) *SettingsHandler { func (h *SettingsHandler) GetSettings(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 } @@ -41,13 +41,13 @@ func (h *SettingsHandler) GetSettings(c *gin.Context) { func (h *SettingsHandler) UpdateSettings(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 } var body map[string]string if err := c.ShouldBindJSON(&body); err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"}) + c.JSON(http.StatusBadRequest, gin.H{"error": "请求格式无效"}) return } tx, err := h.db.Begin() diff --git a/static/js/diff-viewer.js b/static/js/diff-viewer.js index 43e6bd0..9644a0c 100644 --- a/static/js/diff-viewer.js +++ b/static/js/diff-viewer.js @@ -298,7 +298,7 @@ const DiffViewer = { this._onRenderComplete = options.onComplete || null; if (!files || files.length === 0) { - this.container.innerHTML = '
No changes
'; + this.container.innerHTML = '
暂无变更
'; return; } @@ -664,12 +664,12 @@ const DiffViewer = { async loadDiff(repoId, base, head, options = {}) { if (!this.container) return; - this.container.innerHTML = '

Loading diff...

'; + this.container.innerHTML = '

加载 Diff 中...

'; try { const url = `/api/repos/${repoId}/diff?base=${encodeURIComponent(base)}&head=${encodeURIComponent(head)}`; const resp = await fetch(url, { credentials: 'same-origin' }); - if (!resp.ok) throw new Error('Failed to load diff'); + if (!resp.ok) throw new Error('加载 Diff 失败'); const data = await resp.json(); @@ -679,24 +679,24 @@ const DiffViewer = { this.renderFiles(data, options); } } catch (err) { - this.container.innerHTML = `
Error loading diff: ${err.message}
`; + this.container.innerHTML = `
加载 Diff 失败: ${err.message}
`; } }, async loadFiles(repoId, base, head) { if (!this.container) return; - this.container.innerHTML = '

Loading files...

'; + this.container.innerHTML = '

加载文件列表中...

'; try { const url = `/api/repos/${repoId}/diff?base=${encodeURIComponent(base)}&head=${encodeURIComponent(head)}&per_file=true`; const resp = await fetch(url, { credentials: 'same-origin' }); - if (!resp.ok) throw new Error('Failed to load diff'); + if (!resp.ok) throw new Error('加载 Diff 失败'); const files = await resp.json(); this.renderFiles(files); } catch (err) { - this.container.innerHTML = `
Error: ${err.message}
`; + this.container.innerHTML = `
加载失败: ${err.message}
`; } }, diff --git a/static/js/graph.js b/static/js/graph.js index 42c2543..fe7d03c 100644 --- a/static/js/graph.js +++ b/static/js/graph.js @@ -38,7 +38,7 @@ const GitGraph = { async load() { try { const resp = await fetch(`/api/repos/${this.repoId}/graph`, { credentials: 'same-origin' }); - if (!resp.ok) throw new Error('Failed to load graph'); + if (!resp.ok) throw new Error('加载提交图失败'); const data = await resp.json(); this.commits = data.commits || []; @@ -47,7 +47,7 @@ const GitGraph = { this.render(); } catch (err) { - this.container.innerHTML = `
Error loading graph: ${err.message}
`; + this.container.innerHTML = `
加载提交图失败: ${err.message}
`; } }, @@ -59,7 +59,7 @@ const GitGraph = { render() { if (this.commits.length === 0) { - this.container.innerHTML = '
No commits found
'; + this.container.innerHTML = '
暂无提交记录
'; return; } diff --git a/templates/layouts/base.html b/templates/layouts/base.html index 8f21669..7d13ab2 100644 --- a/templates/layouts/base.html +++ b/templates/layouts/base.html @@ -76,7 +76,7 @@ {{define "footer"}} {{end}} diff --git a/templates/pages/generate.html b/templates/pages/generate.html index 1e78226..c930778 100644 --- a/templates/pages/generate.html +++ b/templates/pages/generate.html @@ -92,7 +92,7 @@ async function loadRefs() { try { const resp = await fetch(`/api/repos/${repoId}/refs`, { credentials: 'same-origin' }); - if (!resp.ok) throw new Error('Failed to load refs'); + if (!resp.ok) throw new Error('加载分支列表失败'); const refs = await resp.json(); // Fetch recent commits for the "Recent Commits" group diff --git a/templates/pages/index.html b/templates/pages/index.html index 6a4a240..d9aec84 100644 --- a/templates/pages/index.html +++ b/templates/pages/index.html @@ -142,7 +142,7 @@ document.getElementById('clone-form').addEventListener('submit', async function( if (!resp.ok) { const data = await resp.json(); - throw new Error(data.error || 'clone failed'); + throw new Error(data.error || '克隆失败'); } const reader = resp.body.getReader(); diff --git a/templates/pages/review.html b/templates/pages/review.html index 96e012f..977b76c 100644 --- a/templates/pages/review.html +++ b/templates/pages/review.html @@ -223,7 +223,7 @@ async function loadRefs() { try { const resp = await fetch(`/api/repos/${repoId}/refs`, { credentials: 'same-origin' }); - if (!resp.ok) throw new Error('Failed to load refs'); + if (!resp.ok) throw new Error('加载分支列表失败'); const refs = await resp.json(); // Fetch recent commits for the "Recent Commits" group @@ -576,7 +576,7 @@ try { // Fetch the review result const resp = await fetch(`/api/repos/${repoId}/review/analyses/${analysisId}`, { credentials: 'same-origin' }); - if (!resp.ok) throw new Error('Failed to load review'); + if (!resp.ok) throw new Error('加载评审数据失败'); const data = await resp.json(); const result = data.result;