feat(i18n): replace hardcoded messages with translated strings (#289)

This commit is contained in:
Plynksiy Nikita
2025-06-17 04:05:10 +03:00
committed by GitHub
parent 4b16ad29bb
commit f68ec8f3a1
12 changed files with 49 additions and 14 deletions

View File

@@ -38,7 +38,7 @@ func (f *File) Notify(c *gin.Context) {
res := global.Oss.Verify(c.Request) res := global.Oss.Verify(c.Request)
if !res { if !res {
response.Fail(c, 101, "权限错误") response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
return return
} }
fm := &FileBack{} fm := &FileBack{}

View File

@@ -68,16 +68,16 @@ func (o *Oauth) Confirm(c *gin.Context) {
j := &adminReq.OauthConfirmForm{} j := &adminReq.OauthConfirmForm{}
err := c.ShouldBindJSON(j) err := c.ShouldBindJSON(j)
if err != nil { if err != nil {
response.Fail(c, 101, "参数错误"+err.Error()) response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
return return
} }
if j.Code == "" { if j.Code == "" {
response.Fail(c, 101, "参数错误: code 不存在") response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
return return
} }
v := service.AllService.OauthService.GetOauthCache(j.Code) v := service.AllService.OauthService.GetOauthCache(j.Code)
if v == nil { if v == nil {
response.Fail(c, 101, "授权已过期") response.Fail(c, 101, response.TranslateMsg(c, "OauthExpired"))
return return
} }
u := service.AllService.UserService.CurUser(c) u := service.AllService.UserService.CurUser(c)

View File

@@ -13,13 +13,13 @@ func BackendUserAuth() gin.HandlerFunc {
//测试先关闭 //测试先关闭
token := c.GetHeader("api-token") token := c.GetHeader("api-token")
if token == "" { if token == "" {
response.Fail(c, 403, "请先登录") response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
c.Abort() c.Abort()
return return
} }
user, ut := service.AllService.UserService.InfoByAccessToken(token) user, ut := service.AllService.UserService.InfoByAccessToken(token)
if user.Id == 0 { if user.Id == 0 {
response.Fail(c, 403, "请先登录") response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
c.Abort() c.Abort()
return return
} }

View File

@@ -12,7 +12,7 @@ func AdminPrivilege() gin.HandlerFunc {
u := service.AllService.UserService.CurUser(c) u := service.AllService.UserService.CurUser(c)
if !service.AllService.UserService.IsAdmin(u) { if !service.AllService.UserService.IsAdmin(u) {
response.Fail(c, 403, "无权限") response.Fail(c, 403, response.TranslateMsg(c, "NoAccess"))
c.Abort() c.Abort()
return return
} }

View File

@@ -12,18 +12,18 @@ func JwtAuth() gin.HandlerFunc {
//测试先关闭 //测试先关闭
token := c.GetHeader("api-token") token := c.GetHeader("api-token")
if token == "" { if token == "" {
response.Fail(c, 403, "请先登录") response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
c.Abort() c.Abort()
return return
} }
uid, err := global.Jwt.ParseToken(token) uid, err := global.Jwt.ParseToken(token)
if err != nil { if err != nil {
response.Fail(c, 403, "请先登录") response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
c.Abort() c.Abort()
return return
} }
if uid == 0 { if uid == 0 {
response.Fail(c, 403, "请先登录") response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
c.Abort() c.Abort()
return return
} }
@@ -34,12 +34,12 @@ func JwtAuth() gin.HandlerFunc {
// Username: "测试用户", // Username: "测试用户",
//} //}
if user.Id == 0 { if user.Id == 0 {
response.Fail(c, 403, "请先登录") response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
c.Abort() c.Abort()
return return
} }
if !service.AllService.UserService.CheckUserEnable(user) { if !service.AllService.UserService.CheckUserEnable(user) {
response.Fail(c, 101, "你已被禁用") response.Fail(c, 101, response.TranslateMsg(c, "Banned"))
c.Abort() c.Abort()
return return
} }

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "No access." one = "No access."
other = "No access." other = "No access."
[NeedLogin]
description = "Need login."
one = "Please log in first."
other = "Please log in first."
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "Username or password error." one = "Username or password error."

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "Sin acceso." one = "Sin acceso."
other = "Sin acceso." other = "Sin acceso."
[NeedLogin]
description = "Need login."
one = "Por favor inicie sesión primero."
other = "Por favor inicie sesión primero."
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "Error de usuario o contraseña." one = "Error de usuario o contraseña."

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "Aucun d'access." one = "Aucun d'access."
other = "Aucun d'access." other = "Aucun d'access."
[NeedLogin]
description = "Need login."
one = "Veuillez d'abord vous connecter."
other = "Veuillez d'abord vous connecter."
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "Nom d'utilisateur ou de mot de passe incorrect." one = "Nom d'utilisateur ou de mot de passe incorrect."

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "접근할 수 없습니다." one = "접근할 수 없습니다."
other = "접근할 수 없습니다." other = "접근할 수 없습니다."
[NeedLogin]
description = "Need login."
one = "먼저 로그인해주세요."
other = "먼저 로그인해주세요."
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "사용자 이름이나 비밀번호가 올바르지 않습니다." one = "사용자 이름이나 비밀번호가 올바르지 않습니다."

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "Нет доступа." one = "Нет доступа."
other = "Нет доступа." other = "Нет доступа."
[NeedLogin]
description = "Need login."
one = "Пожалуйста, войдите в систему."
other = "Пожалуйста, войдите в систему."
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "Неправильное имя пользователя или пароль." one = "Неправильное имя пользователя или пароль."

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "无权限。" one = "无权限。"
other = "无权限。" other = "无权限。"
[NeedLogin]
description = "Need login."
one = "请先登录。"
other = "请先登录。"
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "用户名或密码错误。" one = "用户名或密码错误。"

View File

@@ -33,6 +33,11 @@ description = "No access."
one = "無許可權。" one = "無許可權。"
other = "無許可權。" other = "無許可權。"
[NeedLogin]
description = "Need login."
one = "請先登入。"
other = "請先登入。"
[UsernameOrPasswordError] [UsernameOrPasswordError]
description = "Username or password error." description = "Username or password error."
one = "使用者名稱或密碼錯誤。" one = "使用者名稱或密碼錯誤。"