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

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

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

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

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

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

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

+ 2 - 2
http/middleware/admin.go

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

+ 1 - 1
http/middleware/admin_privilege.go

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

+ 5 - 5
http/middleware/jwt.go

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

+ 5 - 0
resources/i18n/en.toml

@@ -33,6 +33,11 @@ description = "No access."
33
 one = "No access."
33
 one = "No access."
34
 other = "No access."
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
 [UsernameOrPasswordError]
41
 [UsernameOrPasswordError]
37
 description = "Username or password error."
42
 description = "Username or password error."
38
 one = "Username or password error."
43
 one = "Username or password error."

+ 5 - 0
resources/i18n/es.toml

@@ -33,6 +33,11 @@ description = "No access."
33
 one = "Sin acceso."
33
 one = "Sin acceso."
34
 other = "Sin acceso."
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
 [UsernameOrPasswordError]
41
 [UsernameOrPasswordError]
37
 description = "Username or password error."
42
 description = "Username or password error."
38
 one = "Error de usuario o contraseña."
43
 one = "Error de usuario o contraseña."

+ 6 - 1
resources/i18n/fr.toml

@@ -33,6 +33,11 @@ description = "No access."
33
 one = "Aucun d'access."
33
 one = "Aucun d'access."
34
 other = "Aucun d'access."
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
 [UsernameOrPasswordError]
41
 [UsernameOrPasswordError]
37
 description = "Username or password error."
42
 description = "Username or password error."
38
 one = "Nom d'utilisateur ou de mot de passe incorrect."
43
 one = "Nom d'utilisateur ou de mot de passe incorrect."
@@ -161,4 +166,4 @@ other = "Banni."
161
 [RegisterSuccessWaitAdminConfirm]
166
 [RegisterSuccessWaitAdminConfirm]
162
 description = "Register success wait admin confirm."
167
 description = "Register success wait admin confirm."
163
 one = "Inscription réussie, veuillez attendre la confirmation de l'administrateur."
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
 one = "접근할 수 없습니다."
33
 one = "접근할 수 없습니다."
34
 other = "접근할 수 없습니다."
34
 other = "접근할 수 없습니다."
35
 
35
 
36
+[NeedLogin]
37
+description = "Need login."
38
+one = "먼저 로그인해주세요."
39
+other = "먼저 로그인해주세요."
40
+
36
 [UsernameOrPasswordError]
41
 [UsernameOrPasswordError]
37
 description = "Username or password error."
42
 description = "Username or password error."
38
 one = "사용자 이름이나 비밀번호가 올바르지 않습니다."
43
 one = "사용자 이름이나 비밀번호가 올바르지 않습니다."

+ 6 - 1
resources/i18n/ru.toml

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

+ 5 - 0
resources/i18n/zh_CN.toml

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

+ 5 - 0
resources/i18n/zh_TW.toml

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