|
|
@@ -3,7 +3,9 @@ package global
|
|
3
|
3
|
import (
|
|
4
|
4
|
"github.com/gin-gonic/gin"
|
|
5
|
5
|
"github.com/go-playground/locales/en"
|
|
|
6
|
+ "github.com/go-playground/locales/ko"
|
|
6
|
7
|
"github.com/go-playground/locales/zh_Hans_CN"
|
|
|
8
|
+
|
|
7
|
9
|
ut "github.com/go-playground/universal-translator"
|
|
8
|
10
|
"github.com/go-playground/validator/v10"
|
|
9
|
11
|
en_translations "github.com/go-playground/validator/v10/translations/en"
|
|
|
@@ -17,11 +19,13 @@ func ApiInitValidator() {
|
|
17
|
19
|
// 定义不同的语言翻译
|
|
18
|
20
|
enT := en.New()
|
|
19
|
21
|
cn := zh_Hans_CN.New()
|
|
|
22
|
+ koT := ko.New()
|
|
20
|
23
|
|
|
21
|
|
- uni := ut.New(enT, cn)
|
|
|
24
|
+ uni := ut.New(enT, cn, koT)
|
|
22
|
25
|
|
|
23
|
26
|
enTrans, _ := uni.GetTranslator("en")
|
|
24
|
27
|
zhTrans, _ := uni.GetTranslator("zh_Hans_CN")
|
|
|
28
|
+ koTrans, _ := uni.GetTranslator("ko")
|
|
25
|
29
|
|
|
26
|
30
|
err := zh_translations.RegisterDefaultTranslations(validate, zhTrans)
|
|
27
|
31
|
if err != nil {
|
|
|
@@ -31,6 +35,11 @@ func ApiInitValidator() {
|
|
31
|
35
|
if err != nil {
|
|
32
|
36
|
panic(err)
|
|
33
|
37
|
}
|
|
|
38
|
+ //validate没有ko的翻译,使用zh的翻译
|
|
|
39
|
+ err = zh_translations.RegisterDefaultTranslations(validate, koTrans)
|
|
|
40
|
+ if err != nil {
|
|
|
41
|
+ panic(err)
|
|
|
42
|
+ }
|
|
34
|
43
|
|
|
35
|
44
|
validate.RegisterTagNameFunc(func(field reflect.StructField) string {
|
|
36
|
45
|
label := field.Tag.Get("label")
|
|
|
@@ -92,6 +101,9 @@ func getTranslatorForLang(lang string) ut.Translator {
|
|
92
|
101
|
case "zh":
|
|
93
|
102
|
trans, _ := Validator.UT.GetTranslator("zh_Hans_CN")
|
|
94
|
103
|
return trans
|
|
|
104
|
+ case "ko":
|
|
|
105
|
+ trans, _ := Validator.UT.GetTranslator("ko")
|
|
|
106
|
+ return trans
|
|
95
|
107
|
case "en":
|
|
96
|
108
|
fallthrough
|
|
97
|
109
|
default:
|