github.com/gogf/gf@v1.16.9/util/gvalid/gvalid_validator_message.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gvalid 8 9 // getErrorMessageByRule retrieves and returns the error message for specified rule. 10 // It firstly retrieves the message from custom message map, and then checks i18n manager, 11 // it returns the default error message if it's not found in custom message map or i18n manager. 12 func (v *Validator) getErrorMessageByRule(ruleKey string, customMsgMap map[string]string) string { 13 content := customMsgMap[ruleKey] 14 if content != "" { 15 // I18n translation. 16 i18nContent := v.i18nManager.GetContent(v.ctx, content) 17 if i18nContent != "" { 18 return i18nContent 19 } 20 return content 21 } 22 // Retrieve default message according to certain rule. 23 content = v.i18nManager.GetContent(v.ctx, ruleMessagePrefixForI18n+ruleKey) 24 if content == "" { 25 content = defaultMessages[ruleKey] 26 } 27 // If there's no configured rule message, it uses default one. 28 if content == "" { 29 content = v.i18nManager.GetContent(v.ctx, ruleMessagePrefixForI18n+internalDefaultRuleName) 30 if content == "" { 31 content = defaultMessages[internalDefaultRuleName] 32 } 33 } 34 return content 35 }