@@ -13,6 +13,19 @@ import (
1313 "gopkg.in/yaml.v3"
1414)
1515
16+ var langFiles = map [string ]string {
17+ "zh" : "lang/zh.yaml" ,
18+ "en" : "lang/en.yaml" ,
19+ "zh-Hant" : "lang/zh-Hant.yaml" ,
20+ "pt-BR" : "lang/pt-BR.yaml" ,
21+ "ja" : "lang/ja.yaml" ,
22+ "ru" : "lang/ru.yaml" ,
23+ "ms" : "lang/ms.yaml" ,
24+ "ko" : "lang/ko.yaml" ,
25+ "tr" : "lang/tr.yaml" ,
26+ "es-ES" : "lang/es-ES.yaml" ,
27+ }
28+
1629func GetMsgWithMap (key string , maps map [string ]interface {}) string {
1730 var content string
1831 if maps == nil {
@@ -123,18 +136,17 @@ func UseI18n() gin.HandlerFunc {
123136func Init () {
124137 bundle = i18n .NewBundle (language .Chinese )
125138 bundle .RegisterUnmarshalFunc ("yaml" , yaml .Unmarshal )
126- _ , _ = bundle .LoadMessageFileFS (fs , "lang/zh.yaml" )
127- _ , _ = bundle .LoadMessageFileFS (fs , "lang/en.yaml" )
128- _ , _ = bundle .LoadMessageFileFS (fs , "lang/zh-Hant.yaml" )
129- _ , _ = bundle .LoadMessageFileFS (fs , "lang/fa.yaml" )
130- _ , _ = bundle .LoadMessageFileFS (fs , "lang/pt.yaml" )
131- _ , _ = bundle .LoadMessageFileFS (fs , "lang/pt-BR.yaml" )
132- _ , _ = bundle .LoadMessageFileFS (fs , "lang/ja.yaml" )
133- _ , _ = bundle .LoadMessageFileFS (fs , "lang/ru.yaml" )
134- _ , _ = bundle .LoadMessageFileFS (fs , "lang/ms.yaml" )
135- _ , _ = bundle .LoadMessageFileFS (fs , "lang/ko.yaml" )
136- _ , _ = bundle .LoadMessageFileFS (fs , "lang/tr.yaml" )
137- _ , _ = bundle .LoadMessageFileFS (fs , "lang/es-ES.yaml" )
139+ isSuccess := true
140+ for _ , file := range langFiles {
141+ if _ , err := bundle .LoadMessageFileFS (fs , file ); err != nil {
142+ global .LOG .Errorf ("[i18n] load language file %s failed: %v\n " , file , err )
143+ isSuccess = false
144+ }
145+ }
146+
147+ if ! isSuccess {
148+ panic ("[i18n] failed to init language files, See log above for details" )
149+ }
138150 lang := GetLanguageFromDB ()
139151 global .I18n = i18n .NewLocalizer (bundle , lang )
140152}
0 commit comments