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
+20 -20
View File
@@ -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 {