Browse Source

add es lang

lejianwen 1 year ago
parent
commit
287bbd43fb
2 changed files with 146 additions and 1 deletions
  1. 12 1
      global/apiValidator.go
  2. 134 0
      resources/i18n/es.toml

+ 12 - 1
global/apiValidator.go

@@ -3,6 +3,7 @@ package global
3
 import (
3
 import (
4
 	"github.com/gin-gonic/gin"
4
 	"github.com/gin-gonic/gin"
5
 	"github.com/go-playground/locales/en"
5
 	"github.com/go-playground/locales/en"
6
+	"github.com/go-playground/locales/es"
6
 	"github.com/go-playground/locales/ko"
7
 	"github.com/go-playground/locales/ko"
7
 	"github.com/go-playground/locales/ru"
8
 	"github.com/go-playground/locales/ru"
8
 	"github.com/go-playground/locales/zh_Hans_CN"
9
 	"github.com/go-playground/locales/zh_Hans_CN"
@@ -10,6 +11,7 @@ import (
10
 	ut "github.com/go-playground/universal-translator"
11
 	ut "github.com/go-playground/universal-translator"
11
 	"github.com/go-playground/validator/v10"
12
 	"github.com/go-playground/validator/v10"
12
 	en_translations "github.com/go-playground/validator/v10/translations/en"
13
 	en_translations "github.com/go-playground/validator/v10/translations/en"
14
+	es_translations "github.com/go-playground/validator/v10/translations/es"
13
 	ru_translations "github.com/go-playground/validator/v10/translations/ru"
15
 	ru_translations "github.com/go-playground/validator/v10/translations/ru"
14
 	zh_translations "github.com/go-playground/validator/v10/translations/zh"
16
 	zh_translations "github.com/go-playground/validator/v10/translations/zh"
15
 	"reflect"
17
 	"reflect"
@@ -23,13 +25,15 @@ func ApiInitValidator() {
23
 	cn := zh_Hans_CN.New()
25
 	cn := zh_Hans_CN.New()
24
 	koT := ko.New()
26
 	koT := ko.New()
25
 	ruT := ru.New()
27
 	ruT := ru.New()
28
+	esT := es.New()
26
 
29
 
27
-	uni := ut.New(enT, cn, koT, ruT)
30
+	uni := ut.New(enT, cn, koT, ruT, esT)
28
 
31
 
29
 	enTrans, _ := uni.GetTranslator("en")
32
 	enTrans, _ := uni.GetTranslator("en")
30
 	zhTrans, _ := uni.GetTranslator("zh_Hans_CN")
33
 	zhTrans, _ := uni.GetTranslator("zh_Hans_CN")
31
 	koTrans, _ := uni.GetTranslator("ko")
34
 	koTrans, _ := uni.GetTranslator("ko")
32
 	ruTrans, _ := uni.GetTranslator("ru")
35
 	ruTrans, _ := uni.GetTranslator("ru")
36
+	esTrans, _ := uni.GetTranslator("es")
33
 
37
 
34
 	err := zh_translations.RegisterDefaultTranslations(validate, zhTrans)
38
 	err := zh_translations.RegisterDefaultTranslations(validate, zhTrans)
35
 	if err != nil {
39
 	if err != nil {
@@ -49,6 +53,10 @@ func ApiInitValidator() {
49
 	if err != nil {
53
 	if err != nil {
50
 		panic(err)
54
 		panic(err)
51
 	}
55
 	}
56
+	err = es_translations.RegisterDefaultTranslations(validate, esTrans)
57
+	if err != nil {
58
+		panic(err)
59
+	}
52
 
60
 
53
 	validate.RegisterTagNameFunc(func(field reflect.StructField) string {
61
 	validate.RegisterTagNameFunc(func(field reflect.StructField) string {
54
 		label := field.Tag.Get("label")
62
 		label := field.Tag.Get("label")
@@ -115,6 +123,9 @@ func getTranslatorForLang(lang string) ut.Translator {
115
 	case "ru":
123
 	case "ru":
116
 		trans, _ := Validator.UT.GetTranslator("ru")
124
 		trans, _ := Validator.UT.GetTranslator("ru")
117
 		return trans
125
 		return trans
126
+	case "es":
127
+		trans, _ := Validator.UT.GetTranslator("es")
128
+		return trans
118
 	case "en":
129
 	case "en":
119
 		fallthrough
130
 		fallthrough
120
 	default:
131
 	default:

+ 134 - 0
resources/i18n/es.toml

@@ -0,0 +1,134 @@
1
+[Test]
2
+description = "test"
3
+one = "prueba1"
4
+other = "Prueba2 {{.P0}}"
5
+
6
+[ParamsError]
7
+description = "Params validation failed."
8
+one = "La validación de los parámetros falló."
9
+other = "La validación de los parámetros falló."
10
+
11
+[OperationFailed]
12
+description = "OperationFailed."
13
+one = "La operación falló."
14
+other = "La operación falló."
15
+
16
+[OperationSuccess]
17
+description = "OperationSuccess."
18
+one = "La operación fue exitosa."
19
+other = "La operación fue exitosa."
20
+
21
+[ItemExists]
22
+description = "Item already exists."
23
+one = "El elemento ya existe."
24
+other = "El elemento ya existe."
25
+
26
+[ItemNotFound]
27
+description = "Item not found."
28
+one = "El elemento no fue encontrado."
29
+other = "El elemento no fue encontrado."
30
+
31
+[NoAccess]
32
+description = "No access."
33
+one = "Sin acceso."
34
+other = "Sin acceso."
35
+
36
+[UsernameOrPasswordError]
37
+description = "Username or password error."
38
+one = "Error de usuario o contraseña."
39
+other = "Error de usuario o contraseña."
40
+
41
+[SystemError]
42
+description = "System error."
43
+one = "Error del sistema."
44
+other = "Error del sistema."
45
+
46
+[ConfigNotFound]
47
+description = "Config not found."
48
+one = "Configuración no encontrada."
49
+other = "Configuración no encontrada."
50
+
51
+[OauthExpired]
52
+description = "Oauth expired."
53
+one = "Oauth expirado, por favor intente nuevamente."
54
+other = "Oauth expirado, por favor intente nuevamente."
55
+
56
+[OauthFailed]
57
+description = "Oauth failed."
58
+one = "Oauth falló."
59
+other = "Oauth falló."
60
+
61
+[OauthHasBindOtherUser]
62
+description = "Oauth has bind other user."
63
+one = "Oauth está vinculado a otro usuario."
64
+other = "Oauth está vinculado a otro usuario."
65
+
66
+[ParamIsEmpty]
67
+description = "Param is empty."
68
+one = "{{.P0}} está vacío."
69
+other = "{{.P0}} está vacío."
70
+
71
+[BindFail]
72
+description = "Bind fail."
73
+one = "Fallo al vincular."
74
+other = "Fallo al vincular."
75
+
76
+[BindSuccess]
77
+description = "Bind success."
78
+one = "Vinculación exitosa."
79
+other = "Vinculación exitosa."
80
+
81
+[OauthHasBeenSuccess]
82
+description = "Oauth has been success."
83
+one = "Oauth fue exitoso."
84
+other = "Oauth fue exitoso."
85
+
86
+[OauthSuccess]
87
+description = "Oauth success."
88
+one = "Oauth exitoso."
89
+other = "Oauth exitoso."
90
+
91
+[OauthRegisterSuccess]
92
+description = "Oauth register success."
93
+one = "Registro de Oauth exitoso."
94
+other = "Registro de Oauth exitoso."
95
+
96
+[OauthRegisterFailed]
97
+description = "Oauth register failed."
98
+one = "Registro de Oauth falló."
99
+other = "Registro de Oauth falló."
100
+
101
+[GetOauthTokenError]
102
+description = "Get oauth token error."
103
+one = "Error al obtener el token de Oauth."
104
+other = "Error al obtener el token de Oauth."
105
+
106
+[GetOauthUserInfoError]
107
+description = "Get oauth user info error."
108
+one = "Error al obtener la información del usuario de Oauth."
109
+other = "Error al obtener la información del usuario de Oauth."
110
+
111
+[DecodeOauthUserInfoError]
112
+description = "Decode oauth user info error."
113
+one = "Error al decodificar la información del usuario de Oauth."
114
+other = "Error al decodificar la información del usuario de Oauth."
115
+
116
+[OldPasswordError]
117
+description = "Old password error."
118
+one = "Error con la contraseña anterior."
119
+other = "Error con la contraseña anterior."
120
+
121
+[DefaultGroup]
122
+description = "Default group"
123
+one = "Grupo predeterminado"
124
+other = "Grupo predeterminado"
125
+
126
+[ShareGroup]
127
+description = "Share group"
128
+one = "Grupo compartido"
129
+other = "Grupo compartido"
130
+
131
+[RegisterClosed]
132
+description = "Register closed."
133
+one = "Registro cerrado."
134
+other = "Registro cerrado."