Skip to content

Commit 1257246

Browse files
authored
feat(i18n): replace hardcoded messages with translated strings (#289)
1 parent 2948eaa commit 1257246

File tree

12 files changed

+49
-14
lines changed

12 files changed

+49
-14
lines changed

http/controller/admin/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (f *File) Notify(c *gin.Context) {
3838

3939
res := global.Oss.Verify(c.Request)
4040
if !res {
41-
response.Fail(c, 101, "权限错误")
41+
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
4242
return
4343
}
4444
fm := &FileBack{}

http/controller/admin/oauth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ func (o *Oauth) Confirm(c *gin.Context) {
6868
j := &adminReq.OauthConfirmForm{}
6969
err := c.ShouldBindJSON(j)
7070
if err != nil {
71-
response.Fail(c, 101, "参数错误"+err.Error())
71+
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
7272
return
7373
}
7474
if j.Code == "" {
75-
response.Fail(c, 101, "参数错误: code 不存在")
75+
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
7676
return
7777
}
7878
v := service.AllService.OauthService.GetOauthCache(j.Code)
7979
if v == nil {
80-
response.Fail(c, 101, "授权已过期")
80+
response.Fail(c, 101, response.TranslateMsg(c, "OauthExpired"))
8181
return
8282
}
8383
u := service.AllService.UserService.CurUser(c)

http/middleware/admin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ func BackendUserAuth() gin.HandlerFunc {
1313
//测试先关闭
1414
token := c.GetHeader("api-token")
1515
if token == "" {
16-
response.Fail(c, 403, "请先登录")
16+
response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
1717
c.Abort()
1818
return
1919
}
2020
user, ut := service.AllService.UserService.InfoByAccessToken(token)
2121
if user.Id == 0 {
22-
response.Fail(c, 403, "请先登录")
22+
response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
2323
c.Abort()
2424
return
2525
}

http/middleware/admin_privilege.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func AdminPrivilege() gin.HandlerFunc {
1212
u := service.AllService.UserService.CurUser(c)
1313

1414
if !service.AllService.UserService.IsAdmin(u) {
15-
response.Fail(c, 403, "无权限")
15+
response.Fail(c, 403, response.TranslateMsg(c, "NoAccess"))
1616
c.Abort()
1717
return
1818
}

http/middleware/jwt.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ func JwtAuth() gin.HandlerFunc {
1212
//测试先关闭
1313
token := c.GetHeader("api-token")
1414
if token == "" {
15-
response.Fail(c, 403, "请先登录")
15+
response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
1616
c.Abort()
1717
return
1818
}
1919
uid, err := global.Jwt.ParseToken(token)
2020
if err != nil {
21-
response.Fail(c, 403, "请先登录")
21+
response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
2222
c.Abort()
2323
return
2424
}
2525
if uid == 0 {
26-
response.Fail(c, 403, "请先登录")
26+
response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
2727
c.Abort()
2828
return
2929
}
@@ -34,12 +34,12 @@ func JwtAuth() gin.HandlerFunc {
3434
// Username: "测试用户",
3535
//}
3636
if user.Id == 0 {
37-
response.Fail(c, 403, "请先登录")
37+
response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
3838
c.Abort()
3939
return
4040
}
4141
if !service.AllService.UserService.CheckUserEnable(user) {
42-
response.Fail(c, 101, "你已被禁用")
42+
response.Fail(c, 101, response.TranslateMsg(c, "Banned"))
4343
c.Abort()
4444
return
4545
}

resources/i18n/en.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ description = "No access."
3333
one = "No access."
3434
other = "No access."
3535

36+
[NeedLogin]
37+
description = "Need login."
38+
one = "Please log in first."
39+
other = "Please log in first."
40+
3641
[UsernameOrPasswordError]
3742
description = "Username or password error."
3843
one = "Username or password error."

resources/i18n/es.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ description = "No access."
3333
one = "Sin acceso."
3434
other = "Sin acceso."
3535

36+
[NeedLogin]
37+
description = "Need login."
38+
one = "Por favor inicie sesión primero."
39+
other = "Por favor inicie sesión primero."
40+
3641
[UsernameOrPasswordError]
3742
description = "Username or password error."
3843
one = "Error de usuario o contraseña."

resources/i18n/fr.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ description = "No access."
3333
one = "Aucun d'access."
3434
other = "Aucun d'access."
3535

36+
[NeedLogin]
37+
description = "Need login."
38+
one = "Veuillez d'abord vous connecter."
39+
other = "Veuillez d'abord vous connecter."
40+
3641
[UsernameOrPasswordError]
3742
description = "Username or password error."
3843
one = "Nom d'utilisateur ou de mot de passe incorrect."
@@ -161,4 +166,4 @@ other = "Banni."
161166
[RegisterSuccessWaitAdminConfirm]
162167
description = "Register success wait admin confirm."
163168
one = "Inscription réussie, veuillez attendre la confirmation de l'administrateur."
164-
other = "Inscription réussie, veuillez attendre la confirmation de l'administrateur."
169+
other = "Inscription réussie, veuillez attendre la confirmation de l'administrateur."

resources/i18n/ko.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ description = "No access."
3333
one = "접근할 수 없습니다."
3434
other = "접근할 수 없습니다."
3535

36+
[NeedLogin]
37+
description = "Need login."
38+
one = "먼저 로그인해주세요."
39+
other = "먼저 로그인해주세요."
40+
3641
[UsernameOrPasswordError]
3742
description = "Username or password error."
3843
one = "사용자 이름이나 비밀번호가 올바르지 않습니다."

resources/i18n/ru.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ description = "No access."
3333
one = "Нет доступа."
3434
other = "Нет доступа."
3535

36+
[NeedLogin]
37+
description = "Need login."
38+
one = "Пожалуйста, войдите в систему."
39+
other = "Пожалуйста, войдите в систему."
40+
3641
[UsernameOrPasswordError]
3742
description = "Username or password error."
3843
one = "Неправильное имя пользователя или пароль."
@@ -161,4 +166,4 @@ other = "Заблокировано."
161166
[RegisterSuccessWaitAdminConfirm]
162167
description = "Register success wait admin confirm."
163168
one = "Регистрация прошла успешно, ожидайте подтверждения администратора."
164-
other = "Регистрация прошла успешно, ожидайте подтверждения администратора."
169+
other = "Регистрация прошла успешно, ожидайте подтверждения администратора."

0 commit comments

Comments
 (0)