package langx import ( "fmt" "strings" ) type MessageKey string // 获取翻译 func GetTrans(key MessageKey, arr map[string]string) (code int, str string) { code = GetCode(key) str = GetMsg(key, arr) return } // 根据Key获取code func GetCode(key MessageKey) int { code, ok := transCode[key] if !ok { return 0 } return code } // 拼接回复 func GetMsg(key MessageKey, arr map[string]string) string { str, ok := transZh[key] if !ok { return string(key) } for k, v := range arr { str = strings.ReplaceAll(str, fmt.Sprintf("#%s#", k), v) } return str }