localeid

package
v0.2.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package localeid canonicalizes and expands BCP 47 locale identifiers.

It isolates language.Tag bridging, likely-subtag maximize behavior, and locale identifier normalization used across Locale and formatter setup.

Only internal locale construction and matching code should use this package; public callers use the locale package.

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

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidUnicodeExtension = errors.New("invalid Unicode locale extension")

Functions

func BaseName added in v0.2.15

func BaseName(tag language.Tag) string

BaseName returns the language identifier without extensions.

func CanonicalUnicodeLanguageSubtag added in v0.2.9

func CanonicalUnicodeLanguageSubtag(subtag string) (string, bool)

CanonicalUnicodeLanguageSubtag validates and lowercases a Unicode language subtag.

func CanonicalUnicodeRegionSubtag added in v0.2.9

func CanonicalUnicodeRegionSubtag(subtag string) (string, bool)

CanonicalUnicodeRegionSubtag validates and uppercases a Unicode region subtag.

func CanonicalUnicodeScriptSubtag added in v0.2.9

func CanonicalUnicodeScriptSubtag(subtag string) (string, bool)

CanonicalUnicodeScriptSubtag validates and title-cases a Unicode script subtag.

func CanonicalUnicodeType added in v0.2.9

func CanonicalUnicodeType(key, value string) (string, bool)

CanonicalUnicodeType validates and lowercases a Unicode locale extension type, then applies the CLDR alias for its key when one exists.

func CanonicalUnicodeVariantSubtag added in v0.2.9

func CanonicalUnicodeVariantSubtag(subtag string) (string, bool)

CanonicalUnicodeVariantSubtag validates and lowercases a Unicode variant subtag.

func InsertUnicodeExtension added in v0.2.6

func InsertUnicodeExtension(locale string, attributes []string, keywords []UnicodeKeyword) string

func IsUnicodeLanguageSubtag added in v0.2.9

func IsUnicodeLanguageSubtag(subtag string) bool

IsUnicodeLanguageSubtag reports whether subtag has Unicode language subtag syntax: 2-3 or 5-8 ASCII letters.

func IsUnicodeRegionSubtag added in v0.2.9

func IsUnicodeRegionSubtag(subtag string) bool

IsUnicodeRegionSubtag reports whether subtag has Unicode region subtag syntax: two ASCII letters or three ASCII digits.

func IsUnicodeScriptSubtag added in v0.2.9

func IsUnicodeScriptSubtag(subtag string) bool

IsUnicodeScriptSubtag reports whether subtag has Unicode script subtag syntax: exactly four ASCII letters.

func IsUnicodeType added in v0.2.9

func IsUnicodeType(value string) bool

IsUnicodeType reports whether value has BCP 47 Unicode locale extension type syntax: one or more 3-8 byte ASCII alphanumeric subtags.

func IsUnicodeVariantSubtag added in v0.2.9

func IsUnicodeVariantSubtag(subtag string) bool

IsUnicodeVariantSubtag reports whether subtag has Unicode variant subtag syntax: 5-8 ASCII alphanumerics, or digit plus three ASCII alphanumerics.

func Join

func Join(lang, script, region string) string

func LowercaseUnicodeLocaleID added in v0.2.9

func LowercaseUnicodeLocaleID(tag string) string

LowercaseUnicodeLocaleID lowercases ASCII letters in a Unicode locale identifier without applying Unicode case folding.

func Maximize

func Maximize(tag string, maximizer SubtagMaximizer) string

func Parts

func Parts(tag language.Tag) (lang, script, region string)

func RelevantExtensionValues added in v0.2.9

func RelevantExtensionValues(defaultValue string, values ...string) []string

RelevantExtensionValues builds the ordered candidate values for one Unicode extension key: default first, then non-empty supported values without duplicates.

func RemoveUnicodeExtension added in v0.2.6

func RemoveUnicodeExtension(tag string) (base, extension string, err error)

func ReplaceLanguageSubtags added in v0.2.15

func ReplaceLanguageSubtags(tag language.Tag, lang, script, region string) (language.Tag, error)

ReplaceLanguageSubtags returns tag with only its language, script, and region replaced. Variants and extensions retain their canonical order.

func VariantSubtags added in v0.2.15

func VariantSubtags(tag language.Tag) []string

VariantSubtags returns the tag's canonical variant subtags.

Types

type SubtagMaximizer

type SubtagMaximizer func(language, script, region string) (lang, scr, reg string, ok bool)

type UnicodeExtension added in v0.2.6

type UnicodeExtension struct {
	// contains filtered or unexported fields
}

func NewUnicodeExtension added in v0.2.6

func NewUnicodeExtension(attributes []string, keywords []UnicodeKeyword) UnicodeExtension

func ParseUnicodeExtension added in v0.2.6

func ParseUnicodeExtension(extension string) (UnicodeExtension, error)

func SplitUnicodeExtension added in v0.2.6

func SplitUnicodeExtension(tag string) (string, UnicodeExtension, error)

func (UnicodeExtension) Attributes added in v0.2.6

func (e UnicodeExtension) Attributes() []string

func (UnicodeExtension) Keywords added in v0.2.6

func (e UnicodeExtension) Keywords() []UnicodeKeyword

func (UnicodeExtension) Parts added in v0.2.6

func (e UnicodeExtension) Parts() []string

func (UnicodeExtension) TypeForKey added in v0.2.6

func (e UnicodeExtension) TypeForKey(key string) (string, bool)

func (UnicodeExtension) ValueForKey added in v0.2.6

func (e UnicodeExtension) ValueForKey(key string) string

type UnicodeKeyword added in v0.2.6

type UnicodeKeyword struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL