From 6eb07514171d9553263c5aa1eb4c546ddfc15a88 Mon Sep 17 00:00:00 2001 From: Dmitri Aleksandrov Date: Mon, 19 Oct 2026 13:22:09 +0300 Subject: [PATCH 1/3] feat(goi18n): translate the messages by a bundle of go-i18n The module github.com/insei/valigo/integrations/goi18n: Source is a translator.Source of a bundle, the messages use the named parameters of the rules, {{.max}}, or the format verbs of the keys, the plural forms are chosen by the first integer argument, the fallback of go-i18n to another language is left to the next sources. Messages exports the built-in messages of a language. --- integrations/goi18n/count_test.go | 28 ++++++ integrations/goi18n/go.mod | 18 ++++ integrations/goi18n/go.sum | 16 +++ integrations/goi18n/goi18n.go | 153 +++++++++++++++++++++++++++++ integrations/goi18n/goi18n_test.go | 96 ++++++++++++++++++ 5 files changed, 311 insertions(+) create mode 100644 integrations/goi18n/count_test.go create mode 100644 integrations/goi18n/go.mod create mode 100644 integrations/goi18n/go.sum create mode 100644 integrations/goi18n/goi18n.go create mode 100644 integrations/goi18n/goi18n_test.go diff --git a/integrations/goi18n/count_test.go b/integrations/goi18n/count_test.go new file mode 100644 index 0000000..3bde4b4 --- /dev/null +++ b/integrations/goi18n/count_test.go @@ -0,0 +1,28 @@ +package goi18n + +import ( + "testing" + + "github.com/nicksnyder/go-i18n/v2/i18n" +) + +func TestCount(t *testing.T) { + for _, arg := range []any{int(3), int8(3), int16(3), int32(3), int64(3), uint(3), uint8(3), uint16(3), uint32(3), uint64(3)} { + if n, ok := count([]any{"x", arg}); !ok || n != 3 { + t.Errorf("count of %T: %d, %v", arg, n, ok) + } + } + if _, ok := count([]any{1.5, "x"}); ok { + t.Error("a float isn't a count") + } +} + +func TestSetForm(t *testing.T) { + m := &i18n.Message{} + for _, c := range []string{"zero", "one", "two", "few", "many", "other"} { + setForm(m, c, c) + } + if *m != (i18n.Message{Zero: "zero", One: "one", Two: "two", Few: "few", Many: "many", Other: "other"}) { + t.Errorf("forms: %+v", m) + } +} diff --git a/integrations/goi18n/go.mod b/integrations/goi18n/go.mod new file mode 100644 index 0000000..584a134 --- /dev/null +++ b/integrations/goi18n/go.mod @@ -0,0 +1,18 @@ +module github.com/insei/valigo/integrations/goi18n + +go 1.27 + +replace github.com/insei/valigo => ../../ + +require ( + github.com/insei/valigo v0.0.0-00010101000000-000000000000 + github.com/nicksnyder/go-i18n/v2 v2.6.1 + github.com/stretchr/testify v1.12.1 + golang.org/x/text v0.43.0 +) + +require ( + github.com/insei/fmap/v3 v3.3.0 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/integrations/goi18n/go.sum b/integrations/goi18n/go.sum new file mode 100644 index 0000000..dd26d99 --- /dev/null +++ b/integrations/goi18n/go.sum @@ -0,0 +1,16 @@ +github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= +github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/insei/fmap/v3 v3.3.0 h1:VdTwCpJxQWyjUqomfNDwRHkWA5XeHnb2UNHB7J2k8UA= +github.com/insei/fmap/v3 v3.3.0/go.mod h1:Kk0gs7nKb4E/JycKJFnrsX5hlyBBe0yetGKFCJG0vzk= +github.com/nicksnyder/go-i18n/v2 v2.6.1 h1:JDEJraFsQE17Dut9HFDHzCoAWGEQJom5s0TRd17NIEQ= +github.com/nicksnyder/go-i18n/v2 v2.6.1/go.mod h1:Vee0/9RD3Quc/NmwEjzzD7VTZ+Ir7QbXocrkhOzmUKA= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= +golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/integrations/goi18n/goi18n.go b/integrations/goi18n/goi18n.go new file mode 100644 index 0000000..c7af2f8 --- /dev/null +++ b/integrations/goi18n/goi18n.go @@ -0,0 +1,153 @@ +// Package goi18n translates the messages of valigo by a bundle of go-i18n (github.com/nicksnyder/go-i18n/v2). +// +// Source is a source of translations of the translator of valigo, the built-in YAML locales translate the rest: +// +// tr := translator.New(translator.WithSources(goi18n.Source(bundle), translator.Embedded())) +// v := valigo.New(valigo.WithTranslator(tr)) +// +// The message IDs are the locale keys of valigo, validation:string:Cannot be longer than %d characters. +// A message can use the named parameters of the rule, {{.max}}, or the format verbs of the key, %d; +// the plural forms are chosen by the first integer argument. Messages exports the built-in messages +// to translate them with your messages. +package goi18n + +import ( + "errors" + "fmt" + "slices" + "strings" + "sync" + + "github.com/nicksnyder/go-i18n/v2/i18n" + "golang.org/x/text/language" + + "github.com/insei/valigo/translator" +) + +// source is the translator.Source of a bundle. +type source struct { + bundle *i18n.Bundle + // localizers are the localizers of the languages, created once + localizers sync.Map +} + +// Source returns the translator.Source of the messages of the bundle. A language without the message in the bundle +// has no translation, the fallback of go-i18n to the default language isn't used: the next sources translate it. +func Source(bundle *i18n.Bundle) translator.Source { + return &source{bundle: bundle} +} + +type localizer struct { + l *i18n.Localizer + base language.Base +} + +func (s *source) localizer(lang string) localizer { + if l, ok := s.localizers.Load(lang); ok { + return l.(localizer) + } + base, _ := language.Make(lang).Base() + l, _ := s.localizers.LoadOrStore(lang, localizer{l: i18n.NewLocalizer(s.bundle, lang), base: base}) + return l.(localizer) +} + +// Translate returns the message of the key in the language, see translator.Source. +func (s *source) Translate(lang, key string, args []any, params map[string]any) (string, bool) { + l := s.localizer(lang) + cfg := &i18n.LocalizeConfig{MessageID: key, TemplateData: params} + if n, ok := count(args); ok { + cfg.PluralCount = n + } + msg, tag, err := l.l.LocalizeWithTag(cfg) + if err != nil { + return "", false + } + if base, _ := tag.Base(); base != l.base { + // the fallback of go-i18n to another language + return "", false + } + if len(args) > 0 && strings.IndexByte(msg, '%') >= 0 { + msg = fmt.Sprintf(msg, args...) + } + return msg, true +} + +// count returns the first integer argument, the count of the plural forms. +func count(args []any) (int64, bool) { + for _, arg := range args { + switch n := arg.(type) { + case int: + return int64(n), true + case int8: + return int64(n), true + case int16: + return int64(n), true + case int32: + return int64(n), true + case int64: + return n, true + case uint: + return int64(n), true + case uint8: + return int64(n), true + case uint16: + return int64(n), true + case uint32: + return int64(n), true + case uint64: + return int64(n), true + } + } + return 0, false +} + +// Messages returns the built-in messages of valigo in the language as the messages of go-i18n, with their plural +// forms, e.g. to add them to a bundle or to write them to the files of the translators. +// The messages keep the format verbs of the keys, %d. +func Messages(lang string) ([]*i18n.Message, error) { + // the embedded locales are valid, the tests of the translator check them + locales, _ := translator.LocalesFromFS(translator.EmbedFSLocalesYAML) + translations, ok := locales[lang] + if !ok { + return nil, errors.New("goi18n: no built-in messages of " + lang) + } + byID := map[string]*i18n.Message{} + var ids []string + for key, value := range translations { + id, category, plural := strings.Cut(key, "#") + m, ok := byID[id] + if !ok { + m = &i18n.Message{ID: id} + byID[id] = m + ids = append(ids, id) + } + if !plural { + category = "other" + } + setForm(m, category, value) + } + slices.Sort(ids) + messages := make([]*i18n.Message, len(ids)) + for i, id := range ids { + messages[i] = byID[id] + } + return messages, nil +} + +// setForm sets the plural form of the CLDR category of the message, other for an unknown category. +func setForm(m *i18n.Message, category, value string) { + switch category { + case "zero": + m.Zero = value + case "one": + m.One = value + case "two": + m.Two = value + case "few": + m.Few = value + case "many": + m.Many = value + default: + m.Other = value + } +} diff --git a/integrations/goi18n/goi18n_test.go b/integrations/goi18n/goi18n_test.go new file mode 100644 index 0000000..bab92b3 --- /dev/null +++ b/integrations/goi18n/goi18n_test.go @@ -0,0 +1,96 @@ +package goi18n_test + +import ( + "context" + "testing" + + "github.com/nicksnyder/go-i18n/v2/i18n" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/text/language" + + "github.com/insei/valigo" + "github.com/insei/valigo/integrations/goi18n" + "github.com/insei/valigo/rules/str" + "github.com/insei/valigo/translator" +) + +const maxRunesKey = "validation:string:Cannot be longer than %d characters" + +type signUp struct { + Name string + Email string + Nick string +} + +func newBundle(t *testing.T) *i18n.Bundle { + t.Helper() + bundle := i18n.NewBundle(language.English) + require.NoError(t, bundle.AddMessages(language.Russian, + &i18n.Message{ID: maxRunesKey, One: "Не длиннее {{.max}} буквы", Few: "Не длиннее {{.max}} букв", Many: "Не длиннее {{.max}} букв", Other: "Не длиннее {{.max}} буквы"}, + &i18n.Message{ID: "nick", Other: "Ник не %s"}, + )) + require.NoError(t, bundle.AddMessages(language.English, &i18n.Message{ID: "validation:string:Should be email address", Other: "An e-mail, please"})) + return bundle +} + +func TestSource(t *testing.T) { + tr := translator.New(translator.WithSources(goi18n.Source(newBundle(t)), translator.Embedded())) + v := valigo.New(valigo.WithTranslator(tr)) + valigo.Configure[signUp](v, func(b valigo.Configurator[signUp], s *signUp) { + b.Field(&s.Name).As(str.Of).MaxRunes(3).MaxRunes(5) + b.Field(&s.Email).As(str.Of).Email() + }) + ctx := translator.ContextWithLanguages(context.Background(), "ru") + var msgs []string + for _, err := range v.ValidateTyped(ctx, &signUp{Name: "Анастасия", Email: "x"}) { + msgs = append(msgs, err.Message) + } + assert.Equal(t, []string{"Не длиннее 3 букв", "Не длиннее 5 букв", "Должно быть электронным адресом"}, msgs, + "the named parameters and the plural forms of go-i18n, the built-in Russian for the rest") + + de := translator.ContextWithLanguages(context.Background(), "de") + msgs = nil + for _, err := range v.ValidateTyped(de, &signUp{Email: "x"}) { + msgs = append(msgs, err.Message) + } + assert.Equal(t, []string{"Muss eine E-Mail-Adresse sein"}, msgs, "the English of the bundle isn't the fallback of German") + + msgs = nil + for _, err := range v.ValidateTyped(context.Background(), &signUp{Email: "x"}) { + msgs = append(msgs, err.Message) + } + assert.Equal(t, []string{"An e-mail, please"}, msgs, "the default language") + + assert.Equal(t, "Ник не x", tr.T(ctx, "nick", "x"), "the format verbs of a key") + assert.Equal(t, "unknown", tr.T(ctx, "unknown")) +} + +func TestMessages(t *testing.T) { + messages, err := goi18n.Messages("ru") + require.NoError(t, err) + var maxRunes *i18n.Message + for _, m := range messages { + if m.ID == maxRunesKey { + maxRunes = m + } + } + require.NotNil(t, maxRunes) + assert.Equal(t, "Не может быть длиннее %d символа", maxRunes.One) + assert.Equal(t, "Не может быть длиннее %d символов", maxRunes.Many) + + // the exported messages in a bundle translate like the built-in ones + bundle := i18n.NewBundle(language.English) + require.NoError(t, bundle.AddMessages(language.Russian, messages...)) + tr := translator.New(translator.WithSources(goi18n.Source(bundle))) + ru := translator.ContextWithLanguages(context.Background(), "ru") + assert.Equal(t, "Не может быть длиннее 21 символа", tr.T(ru, maxRunesKey, 21)) + assert.Equal(t, "Должно быть электронным адресом", tr.T(ru, "validation:string:Should be email address")) + + all, err := goi18n.Messages("en") + require.NoError(t, err) + assert.Len(t, all, len(messages), "every language has every message") + + _, err = goi18n.Messages("xx") + assert.EqualError(t, err, "goi18n: no built-in messages of xx") +} From 587ba99692aae5e89b44fc0928404f193599f68c Mon Sep 17 00:00:00 2001 From: Dmitri Aleksandrov Date: Mon, 19 Oct 2026 13:22:09 +0300 Subject: [PATCH 2/3] ci: lint, test and cover the goi18n module --- .github/dependabot.yml | 1 + scripts/modules.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6ecd4dc..b9fb21d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,6 +7,7 @@ updates: - "/integrations/huma" - "/integrations/gin" - "/integrations/echo" + - "/integrations/goi18n" - "/bench" - "/examples/*" schedule: diff --git a/scripts/modules.sh b/scripts/modules.sh index e752648..7f0841b 100644 --- a/scripts/modules.sh +++ b/scripts/modules.sh @@ -1,3 +1,3 @@ # The separate modules of the repository with their own go.mod, besides the core and the examples. # CI and the scripts lint, test and cover every one of them. -MODULES="rules/uuid integrations/huma integrations/gin integrations/echo" +MODULES="rules/uuid integrations/huma integrations/gin integrations/echo integrations/goi18n" From 8a393a37fc96de3a53a85e8502b9939f8dfde342 Mon Sep 17 00:00:00 2001 From: Dmitri Aleksandrov Date: Mon, 19 Oct 2026 13:22:09 +0300 Subject: [PATCH 3/3] docs: describe the sources of translations and the goi18n module --- README.md | 1 + docs/features/goi18n.md | 66 +++++++++++++++++++++++++++++++++++ docs/features/index.md | 1 + docs/features/translations.md | 27 ++++++++++++++ mkdocs.yml | 2 ++ skills/valigo/SKILL.md | 4 +++ 6 files changed, 101 insertions(+) create mode 100644 docs/features/goi18n.md diff --git a/README.md b/README.md index afd2797..254c198 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ and a conversion that doesn't fit the field doesn't compile: # Errors and translations * Every error has the translated message, the location (`Tags[1]`, `address.city` with JSON paths), the value, a stable `Code` and named `Params` * Messages in English, German, Spanish, French and Russian with plural forms, the language of every request from the context, an `Accept-Language` middleware +* Translations from a chain of sources: your catalogs of [go-i18n](https://github.com/nicksnyder/go-i18n) by `github.com/insei/valigo/integrations/goi18n`, the built-in YAML for the rest, or your own source * `problem`: the errors as `application/problem+json` of RFC 9457 with JSON pointers * The rules as the keywords of JSON Schema, `vhuma.OpenAPI` puts them into the OpenAPI document of huma: the clients see `maxLength`, `format`, `enum` of the rules * `github.com/insei/valigo/integrations/huma`, `github.com/insei/valigo/integrations/gin`, `github.com/insei/valigo/integrations/echo`: the rules of valigo in [huma](https://huma.rocks), [gin](https://gin-gonic.com) and [echo](https://echo.labstack.com) diff --git a/docs/features/goi18n.md b/docs/features/goi18n.md new file mode 100644 index 0000000..cfac008 --- /dev/null +++ b/docs/features/goi18n.md @@ -0,0 +1,66 @@ +# go-i18n + +The module `github.com/insei/valigo/integrations/goi18n` translates the messages of valigo by a bundle of [go-i18n](https://github.com/nicksnyder/go-i18n), so the messages of the validation live in the catalogs of your service with the rest of its texts. + +```bash +go get github.com/insei/valigo/integrations/goi18n@latest +``` + +- `goi18n.Source(bundle)` is a [source of translations](translations.md#sources-of-translations): `translator.WithSources(goi18n.Source(bundle), translator.Embedded())` takes your messages from the bundle and the built-in YAML locales translate the rest. +- The message IDs are the locale keys of valigo, `validation:string:Cannot be longer than %d characters`, see [`translator/locales`](https://github.com/Insei/valigo/tree/main/translator/locales). +- A message uses the named parameters of the rule, `{{.max}}`, `{{.min}}`, `{{.field}}` — the params of the [codes](errors.md#codes-for-clients) — or the format verbs of the key, `%d`. The plural forms are chosen by the first integer argument, `{{.PluralCount}}` is it. +- A language without the message in the bundle has no translation: the fallback of go-i18n to its default language isn't used, the next sources translate the language of the request. +- `goi18n.Messages(lang)` exports the built-in messages of a language with their plural forms, to add them to a bundle or to write them to the files of the translators. + +## Example + +```go +package main + +import ( + "context" + "fmt" + + "github.com/insei/valigo" + "github.com/insei/valigo/integrations/goi18n" + "github.com/insei/valigo/rules/str" + "github.com/insei/valigo/translator" + "github.com/nicksnyder/go-i18n/v2/i18n" + "golang.org/x/text/language" +) + +type SignUp struct { + Name string + Email string +} + +func main() { + bundle := i18n.NewBundle(language.English) + _ = bundle.AddMessages(language.Russian, &i18n.Message{ + ID: "validation:string:Cannot be longer than %d characters", + One: "Имя — не больше {{.max}} буквы", + Few: "Имя — не больше {{.max}} букв", + Many: "Имя — не больше {{.max}} букв", + Other: "Имя — не больше {{.max}} буквы", + }) + + tr := translator.New(translator.WithSources(goi18n.Source(bundle), translator.Embedded())) + v := valigo.New(valigo.WithTranslator(tr)) + valigo.Configure[SignUp](v, func(b valigo.Configurator[SignUp], s *SignUp) { + b.Field(&s.Name).As(str.Of).MaxRunes(3) + b.Field(&s.Email).As(str.Of).Email() + }) + + ctx := translator.ContextWithLanguages(context.Background(), "ru") + for _, err := range v.ValidateTyped(ctx, &SignUp{Name: "Анастасия", Email: "ann"}) { + fmt.Println(err.Location, "-", err.Message) + } +} +``` + +Output: + +```text +Name - Имя — не больше 3 букв +Email - Должно быть электронным адресом +``` diff --git a/docs/features/index.md b/docs/features/index.md index c96e003..ab212e0 100644 --- a/docs/features/index.md +++ b/docs/features/index.md @@ -49,4 +49,5 @@ The separate modules for the frameworks. | [JSON Schema](schema.md) | the rules as the keywords of JSON Schema for the generators of API schemas, `Constraints` | | [huma](huma.md) | `github.com/insei/valigo/integrations/huma`: the rules in the `Resolve` of huma inputs with the locations of huma and in its OpenAPI document | | [gin](gin.md) | `github.com/insei/valigo/integrations/gin`: the `binding.StructValidator` of gin and validation with the language of the request | +| [go-i18n](goi18n.md) | `github.com/insei/valigo/integrations/goi18n`: the messages from a bundle of go-i18n, the built-in ones for the rest | | [echo](echo.md) | `github.com/insei/valigo/integrations/echo`: the `echo.Validator` and validation with the language of the request | diff --git a/docs/features/translations.md b/docs/features/translations.md index 6d4b830..217f5e6 100644 --- a/docs/features/translations.md +++ b/docs/features/translations.md @@ -158,3 +158,30 @@ Output: - `storage.Merge(locales)` adds the translations of several languages at once, e.g. from your own YAML files read by `translator.LocalesFromFS(fsys)`: `locales//data.yaml` with the same nested format as the built-in locales. - `translator.NewInMemStorage(translator.WithInMemData(data))` replaces the built-in locales with yours. - [`str.WithRegexpLocaleKey`](strings.md#regexp-message) sets the key of a `Regexp` rule. + +## Sources of translations + +The translator looks the messages up in its sources: the built-in YAML locales by default, your catalogs of an i18n library, your own source. `translator.WithSources` chains them — for every language of a request in order, the first source with a translation of the key wins: + +```go +tr := translator.New(translator.WithSources(goi18n.Source(bundle), translator.Embedded())) +v := valigo.New(valigo.WithTranslator(tr)) +``` + +Your messages in go-i18n override the built-in ones, the built-in YAML translates the rest; a German request gets the built-in German before your English. `translator.Embedded(opts...)` is the built-in YAML locales as a source, with your additions by `WithInMemData`. + +A source implements `translator.Source`: + +```go +type Source interface { + Translate(lang, key string, args []any, params map[string]any) (string, bool) +} +``` + +`args` are the format arguments of the key, `params` are the same values by their names, `{"max": 64}`, for the libraries with named placeholders; `false` passes the language to the next source. The sources: + +| Source | Module | +|---|---| +| the built-in YAML locales | `translator.Embedded()` | +| [go-i18n](goi18n.md) | `github.com/insei/valigo/integrations/goi18n` | + diff --git a/mkdocs.yml b/mkdocs.yml index 0ee8e2b..8fcd90a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -102,6 +102,7 @@ nav: - huma: features/huma.md - gin: features/gin.md - echo: features/echo.md + - go-i18n: features/goi18n.md - Architecture: - How it works: architecture/index.md @@ -154,5 +155,6 @@ plugins: - features/huma.md: huma inputs, the rules in the OpenAPI document - features/gin.md: gin binding - features/echo.md: echo validator + - features/goi18n.md: the translations of go-i18n bundles Architecture: - architecture/*.md diff --git a/skills/valigo/SKILL.md b/skills/valigo/SKILL.md index e4cf48f..65ef023 100644 --- a/skills/valigo/SKILL.md +++ b/skills/valigo/SKILL.md @@ -186,6 +186,10 @@ func main() { `v.Constraints()` returns the unconditional rules as JSON Schema keywords (`shared.Constraint`: Struct, Field, Path `items`/`additionalProperties`/`propertyNames`, Keyword, Value); rules under `When` aren't described, after `Trim`/`Modify` only `required`. `vhuma.OpenAPI(api, v)` returns the huma document with them in the body schemas (huma's own schemas stay unchanged). Own conversions describe rules by `f.Schema("minimum", 0)`. +## Translation sources + +`translator.New(translator.WithSources(goi18n.Source(bundle), translator.Embedded()))` with `goi18n "github.com/insei/valigo/integrations/goi18n"`: per language of the request, the first source with the key wins; message IDs are the locale keys of valigo, go-i18n messages may use `{{.max}}` (the named params) or `%d`; `goi18n.Messages(lang)` exports the built-in messages. Own source: implement `translator.Source` `Translate(lang, key, args, params) (string, bool)`. + ## gin The module `github.com/insei/valigo/integrations/gin` (`vgin`): `binding.Validator = vgin.New(v)` makes `c.ShouldBindJSON` validate by valigo (messages in the default language, gin passes no request), `vgin.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`, get it by `errors.As`.