Localization & Factory
Valgo ships with localized messages (English default; also Spanish, German, Hungarian) and lets you provide your own locale entries.
Set a locale by code
Section titled “Set a locale by code”val := v.New(v.Options{LocaleCode: "es"}). Check(v.String(" ", "nombre").Not().Blank())Override locale entries
Section titled “Override locale entries”val := v.New(v.Options{ Locale: &v.Locale{ v.ErrorKeyNotBlank: "{{title}} should not be blank", },}).Check(v.String(" ", "name").Not().Blank())Add a new locale
Section titled “Add a new locale”val := v.New(v.Options{ LocaleCode: "ee", Locale: &v.Locale{ v.ErrorKeyNotBlank: "{{title}} ei tohi olla tuhi", },}).Is(v.String(" ", "name").Not().Blank())Custom validator fallback messages
Section titled “Custom validator fallback messages”Custom validators can provide default messages for their own error keys with
ValidatorContext.WithLocaleFallback(...). Fallback entries are merged only
when the active validation locale does not already define the key, so
Options{Locale: ...} overrides still take precedence.
Factory()
Section titled “Factory()”Use a factory to set defaults (locale, custom marshaling) once.
factory := v.Factory(v.FactoryOptions{ LocaleCodeDefault: "es", Locales: map[string]*v.Locale{ "ee": { v.ErrorKeyNotBlank: "{{title}} ei tohi olla tuhi", }, },})
val := factory.Is(v.String(" ", "nombre").Not().Blank())