refactor: clean up form binding & validation (#38873)

Clarify the "validation" and "error display" logic.

All the copied&pasted `Validate` functions are removed.
This commit is contained in:
wxiaoguang
2026-08-14 10:15:33 +08:00
committed by GitHub
parent 8b40df255b
commit 72a9debaff
30 changed files with 331 additions and 737 deletions
+13 -1
View File
@@ -19,6 +19,18 @@ type Locale interface {
HasKey(trKey string) bool
}
// LocaleTranslation represents an interface to translation
type LocaleTranslation interface {
Language() string
HasKey(trKey string) bool
TrString(string, ...any) string
Tr(key string, args ...any) template.HTML
TrN(cnt any, key1, keyN string, args ...any) template.HTML
PrettyNumber(v any) string
}
// LocaleStore provides the functions common to all locale stores
type LocaleStore interface {
io.Closer
@@ -31,7 +43,7 @@ type LocaleStore interface {
Locale(langName string) (Locale, bool)
// HasLang returns whether a given language is present in the store
HasLang(langName string) bool
// AddLocaleByIni adds a new language to the store
// AddLocaleByJSON adds a new language to the store
AddLocaleByJSON(langName, langDesc string, source, moreSource []byte) error
}
+4
View File
@@ -14,6 +14,10 @@ type MockLocale struct {
Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
}
func (l MockLocale) HasKey(trKey string) bool {
return true
}
var _ Locale = (*MockLocale)(nil)
func (l MockLocale) Language() string {
+1 -10
View File
@@ -25,16 +25,7 @@ type contextKey struct{}
var ContextKey any = &contextKey{}
// Locale represents an interface to translation
type Locale interface {
Language() string
TrString(string, ...any) string
Tr(key string, args ...any) template.HTML
TrN(cnt any, key1, keyN string, args ...any) template.HTML
PrettyNumber(v any) string
}
type Locale = i18n.LocaleTranslation
// LangType represents a lang type
type LangType struct {