Просмотр исходного кода

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

Plynksiy Nikita месяцев назад: 7
Родитель
Сommit
1257246552

+ 1 - 1
http/controller/admin/file.go

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

+ 3 - 3
http/controller/admin/oauth.go

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

+ 2 - 2
http/middleware/admin.go

@@ -13,13 +13,13 @@ func BackendUserAuth() gin.HandlerFunc {
13 13
 		//测试先关闭
14 14
 		token := c.GetHeader("api-token")
15 15
 		if token == "" {
16
-			response.Fail(c, 403, "请先登录")
16
+			response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
17 17
 			c.Abort()
18 18
 			return
19 19
 		}
20 20
 		user, ut := service.AllService.UserService.InfoByAccessToken(token)
21 21
 		if user.Id == 0 {
22
-			response.Fail(c, 403, "请先登录")
22
+			response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
23 23
 			c.Abort()
24 24
 			return
25 25
 		}

+ 1 - 1
http/middleware/admin_privilege.go

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

+ 5 - 5
http/middleware/jwt.go

@@ -12,18 +12,18 @@ func JwtAuth() gin.HandlerFunc {
12 12
 		//测试先关闭
13 13
 		token := c.GetHeader("api-token")
14 14
 		if token == "" {
15
-			response.Fail(c, 403, "请先登录")
15
+			response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
16 16
 			c.Abort()
17 17
 			return
18 18
 		}
19 19
 		uid, err := global.Jwt.ParseToken(token)
20 20
 		if err != nil {
21
-			response.Fail(c, 403, "请先登录")
21
+			response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
22 22
 			c.Abort()
23 23
 			return
24 24
 		}
25 25
 		if uid == 0 {
26
-			response.Fail(c, 403, "请先登录")
26
+			response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
27 27
 			c.Abort()
28 28
 			return
29 29
 		}
@@ -34,12 +34,12 @@ func JwtAuth() gin.HandlerFunc {
34 34
 		//	Username: "测试用户",
35 35
 		//}
36 36
 		if user.Id == 0 {
37
-			response.Fail(c, 403, "请先登录")
37
+			response.Fail(c, 403, response.TranslateMsg(c, "NeedLogin"))
38 38
 			c.Abort()
39 39
 			return
40 40
 		}
41 41
 		if !service.AllService.UserService.CheckUserEnable(user) {
42
-			response.Fail(c, 101, "你已被禁用")
42
+			response.Fail(c, 101, response.TranslateMsg(c, "Banned"))
43 43
 			c.Abort()
44 44
 			return
45 45
 		}

+ 5 - 0
resources/i18n/en.toml

@@ -33,6 +33,11 @@ description = "No access."
33 33
 one = "No access."
34 34
 other = "No access."
35 35
 
36
+[NeedLogin]
37
+description = "Need login."
38
+one = "Please log in first."
39
+other = "Please log in first."
40
+
36 41
 [UsernameOrPasswordError]
37 42
 description = "Username or password error."
38 43
 one = "Username or password error."

+ 5 - 0
resources/i18n/es.toml

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

+ 6 - 1
resources/i18n/fr.toml

@@ -33,6 +33,11 @@ description = "No access."
33 33
 one = "Aucun d'access."
34 34
 other = "Aucun d'access."
35 35
 
36
+[NeedLogin]
37
+description = "Need login."
38
+one = "Veuillez d'abord vous connecter."
39
+other = "Veuillez d'abord vous connecter."
40
+
36 41
 [UsernameOrPasswordError]
37 42
 description = "Username or password error."
38 43
 one = "Nom d'utilisateur ou de mot de passe incorrect."
@@ -161,4 +166,4 @@ other = "Banni."
161 166
 [RegisterSuccessWaitAdminConfirm]
162 167
 description = "Register success wait admin confirm."
163 168
 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."

+ 5 - 0
resources/i18n/ko.toml

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

+ 6 - 1
resources/i18n/ru.toml

@@ -33,6 +33,11 @@ description = "No access."
33 33
 one = "Нет доступа."
34 34
 other = "Нет доступа."
35 35
 
36
+[NeedLogin]
37
+description = "Need login."
38
+one = "Пожалуйста, войдите в систему."
39
+other = "Пожалуйста, войдите в систему."
40
+
36 41
 [UsernameOrPasswordError]
37 42
 description = "Username or password error."
38 43
 one = "Неправильное имя пользователя или пароль."
@@ -161,4 +166,4 @@ other = "Заблокировано."
161 166
 [RegisterSuccessWaitAdminConfirm]
162 167
 description = "Register success wait admin confirm."
163 168
 one = "Регистрация прошла успешно, ожидайте подтверждения администратора."
164
-other = "Регистрация прошла успешно, ожидайте подтверждения администратора."
169
+other = "Регистрация прошла успешно, ожидайте подтверждения администратора."

+ 5 - 0
resources/i18n/zh_CN.toml

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

+ 5 - 0
resources/i18n/zh_TW.toml

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