Browse Source

feat(i18n): Add ZH_TW

lejianwen 1 year ago
parent
commit
23c5a96fe1
1 changed files with 18 additions and 4 deletions
  1. 18 4
      global/apiValidator.go

+ 18 - 4
global/apiValidator.go

@@ -4,18 +4,19 @@ import (
4 4
 	"github.com/gin-gonic/gin"
5 5
 	"github.com/go-playground/locales/en"
6 6
 	"github.com/go-playground/locales/es"
7
+	"github.com/go-playground/locales/fr"
7 8
 	"github.com/go-playground/locales/ko"
8 9
 	"github.com/go-playground/locales/ru"
9
-	"github.com/go-playground/locales/fr"
10 10
 	"github.com/go-playground/locales/zh_Hans_CN"
11
-
11
+	"github.com/go-playground/locales/zh_Hant"
12 12
 	ut "github.com/go-playground/universal-translator"
13 13
 	"github.com/go-playground/validator/v10"
14 14
 	en_translations "github.com/go-playground/validator/v10/translations/en"
15 15
 	es_translations "github.com/go-playground/validator/v10/translations/es"
16
+	fr_translations "github.com/go-playground/validator/v10/translations/fr"
16 17
 	ru_translations "github.com/go-playground/validator/v10/translations/ru"
17 18
 	zh_translations "github.com/go-playground/validator/v10/translations/zh"
18
-	fr_translations "github.com/go-playground/validator/v10/translations/fr"
19
+	zh_tw_translations "github.com/go-playground/validator/v10/translations/zh_tw"
19 20
 	"reflect"
20 21
 )
21 22
 
@@ -29,8 +30,9 @@ func ApiInitValidator() {
29 30
 	ruT := ru.New()
30 31
 	esT := es.New()
31 32
 	frT := fr.New()
33
+	zhTwT := zh_Hant.New()
32 34
 
33
-	uni := ut.New(enT, cn, koT, ruT, esT, frT)
35
+	uni := ut.New(enT, cn, koT, ruT, esT, frT, zhTwT)
34 36
 
35 37
 	enTrans, _ := uni.GetTranslator("en")
36 38
 	zhTrans, _ := uni.GetTranslator("zh_Hans_CN")
@@ -38,6 +40,7 @@ func ApiInitValidator() {
38 40
 	ruTrans, _ := uni.GetTranslator("ru")
39 41
 	esTrans, _ := uni.GetTranslator("es")
40 42
 	frTrans, _ := uni.GetTranslator("fr")
43
+	zhTwTrans, _ := uni.GetTranslator("zh_Hant")
41 44
 
42 45
 	err := zh_translations.RegisterDefaultTranslations(validate, zhTrans)
43 46
 	if err != nil {
@@ -65,6 +68,10 @@ func ApiInitValidator() {
65 68
 	if err != nil {
66 69
 		panic(err)
67 70
 	}
71
+	err = zh_tw_translations.RegisterDefaultTranslations(validate, zhTwTrans)
72
+	if err != nil {
73
+		panic(err)
74
+	}
68 75
 
69 76
 	validate.RegisterTagNameFunc(func(field reflect.StructField) string {
70 77
 		label := field.Tag.Get("label")
@@ -125,6 +132,13 @@ func getTranslatorForLang(lang string) ut.Translator {
125 132
 	case "zh":
126 133
 		trans, _ := Validator.UT.GetTranslator("zh_Hans_CN")
127 134
 		return trans
135
+	case "zh_TW":
136
+		fallthrough
137
+	case "zh-TW":
138
+		fallthrough
139
+	case "zh-tw":
140
+		trans, _ := Validator.UT.GetTranslator("zh_Hant")
141
+		return trans
128 142
 	case "ko":
129 143
 		trans, _ := Validator.UT.GetTranslator("ko")
130 144
 		return trans