mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-16 01:45:11 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user