Documentation
¶
Overview ¶
Package gointl provides the root ECMA-402 Intl namespace for Go.
It exposes common namespace functions and aliases for the active Intl.Locale, Intl.NumberFormat, Intl.DateTimeFormat, Intl.PluralRules, Intl.ListFormat, Intl.RelativeTimeFormat, Intl.DurationFormat, Intl.DisplayNames, Intl.Collator, and Intl.Segmenter constructor packages. Formatter construction and formatting methods live in those packages.
Import formatter subpackages directly when an application needs one constructor. Importing this root package is an aggregate facade and pulls the active constructor packages so namespace aliases remain available. Measure root dependency and binary-size reports as aggregate facade cost; measure formatter subpackages separately for single-constructor services.
Errors ¶
Formatter construction and formatting errors wrap the root error categories. Callers classify errors with errors.Is, not by matching strings. Suggested mappings are for applications that expose this library through HTTP, gRPC, CLI, or another user boundary.
ErrInvalidOption is returned when constructor or SupportedLocalesOf option validation rejects an option name/value combination. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrInvalidOption)
Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit.
ErrUnsupportedOption is returned when a valid ECMA-402 option is not backed by the active implementation. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrUnsupportedOption)
It also matches errors.ErrUnsupported. Caller pattern:
errors.Is(err, errors.ErrUnsupported)
Suggested mapping: unsupported capability, such as HTTP 501 or a clear CLI unsupported-feature message.
ErrInvalidValue is returned when a runtime formatting value is malformed, non-finite, or otherwise outside the target Intl operation. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrInvalidValue)
Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit.
ErrInvalidCode is returned when DisplayNames.Of receives a code outside its resolved type. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrInvalidCode)
Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit.
Public caller-fixable errors also expose *gointl.Error. Caller pattern:
detail, ok := errors.AsType[*gointl.Error](err)
Error fields are stable machine-readable context: Kind is the root category; Owner is the Intl package or root namespace; Name is the option, argument, key, code, or field; Value is the rejected value and can be empty when the invalid input was omitted; Locale is set only for locale-dependent failures; Expected is human guidance; Err is the wrapped sentinel or underlying cause.
Example (DateTimeFormat) ¶
package main
import (
"fmt"
"time"
gointl "github.com/agentable/go-intl"
"github.com/agentable/go-intl/datetimeformat"
"github.com/agentable/go-intl/locale"
)
func main() {
format, err := datetimeformat.New(mustLocaleList("en-US"), datetimeformat.Options{
Year: gointl.String(string(datetimeformat.NumericFieldStyle)),
Month: gointl.String(string(datetimeformat.ShortMonthStyle)),
Day: gointl.String(string(datetimeformat.NumericFieldStyle)),
TimeZone: gointl.String("UTC"),
})
if err != nil {
panic(err)
}
fmt.Println(format.Format(time.Date(2026, time.May, 8, 0, 0, 0, 0, time.UTC)))
}
func mustLocaleList(tags ...string) locale.List {
locales, err := locale.ParseList(tags...)
if err != nil {
panic(err)
}
return locales
}
Output: May 8, 2026
Example (DirectFormatter) ¶
package main
import (
"fmt"
gointl "github.com/agentable/go-intl"
"github.com/agentable/go-intl/locale"
"github.com/agentable/go-intl/numberformat"
)
func main() {
format, err := numberformat.New(mustLocaleList("en-US"), numberformat.Options{
Style: gointl.String(numberformat.CurrencyStyle),
Currency: gointl.String("EUR"),
})
if err != nil {
panic(err)
}
fmt.Println(format.Format(numberformat.Float(1234.5)))
}
func mustLocaleList(tags ...string) locale.List {
locales, err := locale.ParseList(tags...)
if err != nil {
panic(err)
}
return locales
}
Output:
Example (ErrorKind) ¶
Example_errorKind classifies a constructor error by category through the exported Error.Kind field and the root ErrorKind constants — the struct-based alternative to errors.Is against a sentinel.
package main
import (
"errors"
"fmt"
gointl "github.com/agentable/go-intl"
"github.com/agentable/go-intl/locale"
"github.com/agentable/go-intl/numberformat"
)
func main() {
_, err := numberformat.New(mustLocaleList("en-US"), numberformat.Options{
Style: gointl.String(numberformat.CurrencyStyle),
Currency: gointl.String("US"), // not a 3-letter ISO 4217 code
})
var intlErr *gointl.Error
if errors.As(err, &intlErr) {
switch intlErr.Kind {
case gointl.InvalidOption:
fmt.Println("invalid option:", intlErr.Name)
default:
fmt.Println("other:", intlErr.Kind)
}
}
}
func mustLocaleList(tags ...string) locale.List {
locales, err := locale.ParseList(tags...)
if err != nil {
panic(err)
}
return locales
}
Output: invalid option: currency
Example (GetCanonicalLocales) ¶
package main
import (
"fmt"
gointl "github.com/agentable/go-intl"
"github.com/agentable/go-intl/locale"
)
func main() {
locales := mustLocaleList("en-us", "en-US", "zh-Hans-CN-u-nu-latn")
for _, loc := range gointl.GetCanonicalLocales(locales) {
fmt.Println(loc.String())
}
}
func mustLocaleList(tags ...string) locale.List {
locales, err := locale.ParseList(tags...)
if err != nil {
panic(err)
}
return locales
}
Output: en-US zh-Hans-CN-u-nu-latn
Example (NumberFormat) ¶
package main
import (
"fmt"
gointl "github.com/agentable/go-intl"
"github.com/agentable/go-intl/locale"
"github.com/agentable/go-intl/numberformat"
)
func main() {
format, err := numberformat.New(mustLocaleList("en-US"), numberformat.Options{
Style: gointl.String(numberformat.CurrencyStyle),
Currency: gointl.String("USD"),
})
if err != nil {
panic(err)
}
fmt.Println(format.Format(numberformat.Float(1234.5)))
}
func mustLocaleList(tags ...string) locale.List {
locales, err := locale.ParseList(tags...)
if err != nil {
panic(err)
}
return locales
}
Output: $1,234.50
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func GetCanonicalLocales(locales locale.List) locale.List
- func Int(v int) *int
- func String[T ~string](v T) *string
- func SupportedCalendars() []string
- func SupportedCollations() []string
- func SupportedCurrencies() []string
- func SupportedNumberingSystems() []string
- func SupportedTimeZones() []string
- func SupportedUnits() []string
- type Collator
- type DateTimeFormat
- type DisplayNames
- type DurationFormat
- type Error
- type ErrorKind
- type ListFormat
- type Locale
- type NumberFormat
- type PluralRules
- type RelativeTimeFormat
- type Segmenter
Examples ¶
Constants ¶
const ( // InvalidOption is the Error.Kind for ECMA-402 RangeError-equivalent option failures. InvalidOption = intlerr.InvalidOption // UnsupportedOption is the Error.Kind for valid options the active backend cannot apply. UnsupportedOption = intlerr.UnsupportedOption // InvalidValue is the Error.Kind for malformed or non-finite runtime values. InvalidValue = intlerr.InvalidValue // InvalidCode is the Error.Kind for invalid DisplayNames code inputs. InvalidCode = intlerr.InvalidCode )
Variables ¶
var ( // ErrInvalidOption classifies constructor and SupportedLocalesOf option // validation failures. It is a standalone category sentinel. // // Caller pattern: // // errors.Is(err, gointl.ErrInvalidOption) // // Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit. ErrInvalidOption = intlerr.ErrInvalidOption // ErrUnsupportedOption classifies valid ECMA-402 options not backed by the // active implementation. It is a standalone category sentinel and also // matches errors.ErrUnsupported. // // Caller pattern: // // errors.Is(err, gointl.ErrUnsupportedOption) // // Suggested mapping: an unsupported-capability response. ErrUnsupportedOption = intlerr.ErrUnsupportedOption // ErrInvalidValue classifies malformed, non-finite, or otherwise invalid // runtime formatting values. It is a standalone category sentinel. // // Caller pattern: // // errors.Is(err, gointl.ErrInvalidValue) // // Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit. ErrInvalidValue = intlerr.ErrInvalidValue // ErrInvalidCode classifies DisplayNames.Of codes outside the formatter's // resolved type. It is a standalone category sentinel. // // Caller pattern: // // errors.Is(err, gointl.ErrInvalidCode) // // Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit. ErrInvalidCode = intlerr.ErrInvalidCode )
Functions ¶
func Bool ¶
Bool returns a pointer to v for optional boolean Options fields. Re-exports option.Bool; see Int for the single-formatter import guidance.
func GetCanonicalLocales ¶
GetCanonicalLocales returns the Intl.getCanonicalLocales canonical locale list.
It keeps the first occurrence of each canonical locale while preserving request order. Raw locale string parsing stays with the locale package.
func Int ¶
Int returns a pointer to v for optional integer Options fields.
It re-exports option.Int for namespace fidelity. Single-formatter services should import the zero-dependency github.com/agentable/go-intl/option package directly instead of the aggregate root.
func String ¶
String returns a pointer to v for optional string Options fields. Re-exports option.String; see Int for the single-formatter import guidance.
func SupportedCalendars ¶
func SupportedCalendars() []string
SupportedCalendars returns the calendar identifiers for Intl.supportedValuesOf("calendar").
The returned slice is sorted, canonical, and independent.
func SupportedCollations ¶
func SupportedCollations() []string
SupportedCollations returns the active Collator backend collation identifiers for Intl.supportedValuesOf("collation").
The returned slice is sorted, canonical, and independent.
func SupportedCurrencies ¶
func SupportedCurrencies() []string
SupportedCurrencies returns the currency identifiers for Intl.supportedValuesOf("currency").
The returned slice is sorted, canonical, and independent.
func SupportedNumberingSystems ¶
func SupportedNumberingSystems() []string
SupportedNumberingSystems returns the numbering-system identifiers for Intl.supportedValuesOf("numberingSystem").
The returned slice is sorted, canonical, and independent.
func SupportedTimeZones ¶
func SupportedTimeZones() []string
SupportedTimeZones returns the primary IANA time-zone identifiers for Intl.supportedValuesOf("timeZone").
The returned slice is sorted, canonical, and independent.
func SupportedUnits ¶
func SupportedUnits() []string
SupportedUnits returns the sanctioned unit identifiers for Intl.supportedValuesOf("unit").
The returned slice is sorted, canonical, and independent.
Types ¶
type Collator ¶
Collator is the root Intl.Collator constructor-property alias for collator.Collator.
type DateTimeFormat ¶
type DateTimeFormat = datetimeformat.DateTimeFormat
DateTimeFormat is the root Intl.DateTimeFormat constructor-property alias for datetimeformat.DateTimeFormat.
type DisplayNames ¶
type DisplayNames = displaynames.DisplayNames
DisplayNames is the root Intl.DisplayNames constructor-property alias for displaynames.DisplayNames.
type DurationFormat ¶
type DurationFormat = durationformat.DurationFormat
DurationFormat is the root Intl.DurationFormat constructor-property alias for durationformat.DurationFormat.
type Error ¶
Error records structured context for caller-fixable Intl failures. Kind is the root category; Owner is the Intl package or root namespace; Name is the rejected option, argument, key, code, or field; Value is the rejected value and can be empty; Locale is empty unless the failure is locale-dependent; Expected is human guidance; and Err wraps the category sentinel plus any underlying cause.
Caller pattern:
detail, ok := errors.AsType[*gointl.Error](err)
Suggested mapping: choose the external invalid-input or unsupported- capability response from detail.Kind; do not expose Error() text directly.
type ErrorKind ¶
ErrorKind is the category of an Error, readable from Error.Kind after extracting the detail with errors.AsType[*gointl.Error]. The constants below are its legal values. Prefer errors.Is with a category sentinel when the structured fields are not needed.
type ListFormat ¶
type ListFormat = listformat.ListFormat
ListFormat is the root Intl.ListFormat constructor-property alias for listformat.ListFormat.
type NumberFormat ¶
type NumberFormat = numberformat.NumberFormat
NumberFormat is the root Intl.NumberFormat constructor-property alias for numberformat.NumberFormat.
type PluralRules ¶
type PluralRules = pluralrules.PluralRules
PluralRules is the root Intl.PluralRules constructor-property alias for pluralrules.PluralRules.
type RelativeTimeFormat ¶
type RelativeTimeFormat = relativetimeformat.RelativeTimeFormat
RelativeTimeFormat is the root Intl.RelativeTimeFormat constructor-property alias for relativetimeformat.RelativeTimeFormat.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package collator implements the ECMA-402 Intl.Collator constructor.
|
Package collator implements the ECMA-402 Intl.Collator constructor. |
|
Package datetimeformat implements the ECMA-402 Intl.DateTimeFormat constructor.
|
Package datetimeformat implements the ECMA-402 Intl.DateTimeFormat constructor. |
|
Package displaynames implements the ECMA-402 Intl.DisplayNames constructor.
|
Package displaynames implements the ECMA-402 Intl.DisplayNames constructor. |
|
Package durationformat implements the ECMA-402 Intl.DurationFormat constructor.
|
Package durationformat implements the ECMA-402 Intl.DurationFormat constructor. |
|
internal
|
|
|
cldr/codec
Package codec provides the lowest-level hand-written decode primitives that every cldr domain package builds on.
|
Package codec provides the lowest-level hand-written decode primitives that every cldr domain package builds on. |
|
cldr/currency
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/date
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/displaynames
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/list
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/locale
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/number
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/plural
Package plural exposes generated CLDR plural-rule data.
|
Package plural exposes generated CLDR plural-rule data. |
|
cldr/relativetime
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/timezone
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
cldr/unit
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention
|
Source: CLDR v48.1.0 / ICU 78 / tzdata 2025b (input hashes in internal/cldr/locale/manifest.go) Generated: reproducible from tools/gen-cldr with pinned inputs; no timestamps or machine-local paths Schema: SPECS/50-cldr-data.md#cldr-data-package-convention |
|
collation
Package collation exposes the locale tags supported by the embedded collator.
|
Package collation exposes the locale tags supported by the embedded collator. |
|
decimal
Package decimal provides decimal arithmetic for ECMA-402 mathematical values.
|
Package decimal provides decimal arithmetic for ECMA-402 mathematical values. |
|
ecma402
Package ecma402 implements shared ECMA-402 abstract operations.
|
Package ecma402 implements shared ECMA-402 abstract operations. |
|
intlerr
Package intlerr provides the cycle-free implementation behind the root Intl error surface.
|
Package intlerr provides the cycle-free implementation behind the root Intl error surface. |
|
intltest
Package intltest provides shared test helpers for go-intl packages.
|
Package intltest provides shared test helpers for go-intl packages. |
|
localeid
Package localeid canonicalizes and expands BCP 47 locale identifiers.
|
Package localeid canonicalizes and expands BCP 47 locale identifiers. |
|
localematcher
Package localematcher implements ECMA-402 locale matching.
|
Package localematcher implements ECMA-402 locale matching. |
|
numbering
Package numbering exposes ECMA-402 numbering-system metadata.
|
Package numbering exposes ECMA-402 numbering-system metadata. |
|
pattern
Package pattern parses brace-delimited formatter patterns.
|
Package pattern parses brace-delimited formatter patterns. |
|
plural
Package plural evaluates generated CLDR plural rules.
|
Package plural evaluates generated CLDR plural rules. |
|
segmentation
Package segmentation exposes the locale tags supported by the embedded segmenter.
|
Package segmentation exposes the locale tags supported by the embedded segmenter. |
|
testcontract
Package testcontract provides small reusable assertions for repository-wide test contracts.
|
Package testcontract provides small reusable assertions for repository-wide test contracts. |
|
testprocess
Package testprocess provides subprocess helpers for tests that need clean package-level state.
|
Package testprocess provides subprocess helpers for tests that need clean package-level state. |
|
tz
Package tz resolves ECMA-402 time-zone identifiers.
|
Package tz resolves ECMA-402 time-zone identifiers. |
|
unitid
Package unitid owns ECMA-402 measurement unit identifier facts.
|
Package unitid owns ECMA-402 measurement unit identifier facts. |
|
Package listformat implements the ECMA-402 Intl.ListFormat constructor.
|
Package listformat implements the ECMA-402 Intl.ListFormat constructor. |
|
Package locale implements the ECMA-402 Intl.Locale constructor.
|
Package locale implements the ECMA-402 Intl.Locale constructor. |
|
Package numberformat implements the ECMA-402 Intl.NumberFormat constructor.
|
Package numberformat implements the ECMA-402 Intl.NumberFormat constructor. |
|
Package option provides the pointer constructors for optional scalar Intl options (*int, *bool, *string).
|
Package option provides the pointer constructors for optional scalar Intl options (*int, *bool, *string). |
|
Package pluralrules implements the ECMA-402 Intl.PluralRules constructor.
|
Package pluralrules implements the ECMA-402 Intl.PluralRules constructor. |
|
Package relativetimeformat implements the ECMA-402 Intl.RelativeTimeFormat constructor.
|
Package relativetimeformat implements the ECMA-402 Intl.RelativeTimeFormat constructor. |
|
Package segmenter implements the ECMA-402 Intl.Segmenter constructor.
|
Package segmenter implements the ECMA-402 Intl.Segmenter constructor. |
|
tools
|
|
|
check-conformance
command
|
|
|
check-generated-data
command
|
|
|
conformance
Package conformance loads and filters ECMA-402 conformance fixtures.
|
Package conformance loads and filters ECMA-402 conformance fixtures. |
|
data-preflight
command
|
|
|
internal/localeprofile
Package localeprofile owns the tools/locale-profile.json contract shared by CLDR-backed generators.
|
Package localeprofile owns the tools/locale-profile.json contract shared by CLDR-backed generators. |
|
node-witness
command
|
|
|
sizecheck
command
|