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.
ErrInvalidKey is returned when a root namespace key is outside the ECMA-402 supported set. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrInvalidKey)
Suggested mapping: invalid caller input, such as HTTP 400 or CLI usage exit.
ErrUnsupportedLocale is returned when locale negotiation cannot satisfy a requested locale with the active data set. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrUnsupportedLocale)
It also matches errors.ErrUnsupported. Caller pattern:
errors.Is(err, errors.ErrUnsupported)
Suggested mapping: unsupported locale input, such as HTTP 400 or 406 depending on the host API contract.
ErrUnsupportedBackend is returned when required implementation support is unavailable. It is a standalone category sentinel. Caller pattern:
errors.Is(err, gointl.ErrUnsupportedBackend)
It also matches errors.ErrUnsupported. Caller pattern:
errors.Is(err, errors.ErrUnsupported)
Suggested mapping: service/configuration capability failure, such as HTTP 500 or 503.
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"
"github.com/agentable/go-intl/datetimeformat"
"github.com/agentable/go-intl/locale"
)
func main() {
format, err := datetimeformat.New(mustLocaleList("en-US"), datetimeformat.Options{
Year: datetimeformat.NumericFieldStyle,
Month: datetimeformat.ShortMonthStyle,
Day: datetimeformat.NumericFieldStyle,
})
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"
"github.com/agentable/go-intl/locale"
"github.com/agentable/go-intl/numberformat"
)
func main() {
format, err := numberformat.New(mustLocaleList("en-US"), numberformat.Options{
Style: numberformat.CurrencyStyle,
Currency: numberformat.Currency("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 (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"
"github.com/agentable/go-intl/locale"
"github.com/agentable/go-intl/numberformat"
)
func main() {
format, err := numberformat.New(mustLocaleList("en-US"), numberformat.Options{
Style: numberformat.CurrencyStyle,
Currency: numberformat.Currency("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(v string) *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 = intlerr.InvalidOption UnsupportedOption = intlerr.UnsupportedOption InvalidValue = intlerr.InvalidValue InvalidCode = intlerr.InvalidCode InvalidKey = intlerr.InvalidKey UnsupportedLocale = intlerr.UnsupportedLocale UnsupportedBackend = intlerr.UnsupportedBackend )
Variables ¶
var ( // ErrInvalidOption classifies ECMA-402 RangeError-equivalent option failures. ErrInvalidOption = intlerr.ErrInvalidOption // ErrUnsupportedOption classifies valid options not backed by the active implementation. ErrUnsupportedOption = intlerr.ErrUnsupportedOption // ErrInvalidValue classifies malformed or non-finite runtime values. ErrInvalidValue = intlerr.ErrInvalidValue // ErrInvalidCode classifies invalid DisplayNames code inputs. ErrInvalidCode = intlerr.ErrInvalidCode // ErrInvalidKey classifies invalid root namespace keys. ErrInvalidKey = intlerr.ErrInvalidKey // ErrUnsupportedLocale classifies locale requests outside the active data set. ErrUnsupportedLocale = intlerr.ErrUnsupportedLocale // ErrUnsupportedBackend classifies unavailable required implementation support. ErrUnsupportedBackend = intlerr.ErrUnsupportedBackend )
Functions ¶
func SupportedCalendars ¶
func SupportedCalendars() []string
func SupportedCollations ¶
func SupportedCollations() []string
func SupportedCurrencies ¶
func SupportedCurrencies() []string
func SupportedNumberingSystems ¶
func SupportedNumberingSystems() []string
func SupportedTimeZones ¶
func SupportedTimeZones() []string
func SupportedUnits ¶
func SupportedUnits() []string
Types ¶
type DateTimeFormat ¶
type DateTimeFormat = datetimeformat.DateTimeFormat
type DisplayNames ¶
type DisplayNames = displaynames.DisplayNames
type DurationFormat ¶
type DurationFormat = durationformat.DurationFormat
type ListFormat ¶
type ListFormat = listformat.ListFormat
type NumberFormat ¶
type NumberFormat = numberformat.NumberFormat
type PluralRules ¶
type PluralRules = pluralrules.PluralRules
type RelativeTimeFormat ¶
type RelativeTimeFormat = 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. |
|
tz
Package tz resolves ECMA-402 time-zone identifiers.
|
Package tz resolves ECMA-402 time-zone identifiers. |
|
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 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
|
|
|
conformance
Package conformance loads and filters ECMA-402 conformance fixtures.
|
Package conformance loads and filters ECMA-402 conformance fixtures. |
|
node-witness
command
|
|
|
sizecheck
command
|