Skip to content

v0.8.0

Latest

Choose a tag to compare

@kaptinlin kaptinlin released this 05 Jun 14:30
· 2 commits to main since this release

Localization moved to the optional i18n subpackage

The root package no longer imports any translation framework. Pure validation users pay zero Intl compile, link, and binary cost — 28 transitive packages dropped from the root import graph, and not a single byte of locale data ends up in your binary unless you opt in.

Localization is now opt-in through the consumer-side Translator interface:

type Translator interface {
    Translate(code string, params map[string]any) (message string, ok bool)
}

The i18n subpackage provides the built-in 9-locale implementation (backed by go-i18n); or implement the one-method interface yourself with any backend.

Migration

Before After
jsonschema.I18n() + bundle.NewLocalizer("zh-Hans") i18n.New("zh-Hans") — import github.com/kaptinlin/jsonschema/i18n
err.Localize(localizer) err.Localize(translator)
result.ToLocalizeList(localizer, ...) result.ToLocalizedList(translator, ...)
result.DetailedErrors(localizer) result.LocalizedDetailedErrors(translator)
result.DetailedErrors() unchanged — always English, no arguments
import (
    "github.com/kaptinlin/jsonschema"
    "github.com/kaptinlin/jsonschema/i18n"
)

zh, err := i18n.New("zh-Hans") // one translator per locale; unknown locale errors here
if err != nil { ... }

for path, msg := range result.LocalizedDetailedErrors(zh) {
    fmt.Println(path, msg)
}

Behavior

  • Fallback semantics unchanged: a nil translator or a missing translation falls back to the built-in English message — localization never fails.
  • Same 9 built-in locales: en, de-DE, es-ES, fr-FR, ja-JP, ko-KR, pt-BR, zh-Hans, zh-Hant.
  • i18n.New rejects unknown locales with ErrUnsupportedLocale instead of silently falling back to English.

Dependencies

  • go-i18n upgraded to v0.5.0 (now uses messageformat-go/mf1 v0.7.0).

Full Changelog: v0.7.18...v0.8.0