...

Package language

import "cmd/vendor/golang.org/x/text/internal/language"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Constants
Variables
func ParseExtension(s string) (ext string, err error)
type AliasType
type Builder
    func (b *Builder) AddExt(e string)
    func (b *Builder) AddVariant(v ...string)
    func (b *Builder) ClearExtensions()
    func (b *Builder) ClearVariants()
    func (b *Builder) Make() Tag
    func (b *Builder) SetExt(e string)
    func (b *Builder) SetTag(t Tag)
type CompactCoreInfo
    func GetCompactCore(t Tag) (cci CompactCoreInfo, ok bool)
    func (c CompactCoreInfo) Tag() Tag
type FromTo
type Language
    func BaseLanguages() []Language
    func MustParseBase(s string) Language
    func ParseBase(s string) (l Language, err error)
    func (id Language) Canonicalize() (Language, AliasType)
    func (b Language) ISO3() string
    func (b Language) IsPrivateUse() bool
    func (b Language) String() string
    func (id Language) StringToBuf(b []byte) int
    func (b Language) SuppressScript() Script
type Region
    func EncodeM49(r int) (Region, error)
    func MustParseRegion(s string) Region
    func ParseRegion(s string) (r Region, err error)
    func (r Region) Canonicalize() Region
    func (r Region) Contains(c Region) bool
    func (r Region) ISO3() string
    func (r Region) IsCountry() bool
    func (r Region) IsGroup() bool
    func (r Region) IsPrivateUse() bool
    func (r Region) M49() int
    func (r Region) String() string
    func (r Region) TLD() (Region, error)
type Script
    func MustParseScript(s string) Script
    func ParseScript(s string) (scr Script, err error)
    func (s Script) IsPrivateUse() bool
    func (s Script) String() string
type Tag
    func Make(s string) Tag
    func MustParse(s string) Tag
    func Parse(s string) (t Tag, err error)
    func (t Tag) Extension(x byte) (ext string, ok bool)
    func (t Tag) Extensions() []string
    func (t Tag) HasExtensions() bool
    func (t Tag) HasString() bool
    func (t Tag) HasVariants() bool
    func (t Tag) IsPrivateUse() bool
    func (t Tag) IsRoot() bool
    func (t Tag) MarshalText() (text []byte, err error)
    func (t Tag) Maximize() (Tag, error)
    func (t Tag) Parent() Tag
    func (t Tag) Raw() (b Language, s Script, r Region)
    func (t *Tag) RemakeString()
    func (t Tag) SetTypeForKey(key, value string) (Tag, error)
    func (t Tag) String() string
    func (t Tag) TypeForKey(key string) string
    func (t *Tag) UnmarshalText(text []byte) error
    func (t Tag) VariantOrPrivateUseTags() string
    func (t Tag) Variants() string
type ValueError
    func NewValueError(tag []byte) ValueError
    func (e ValueError) Error() string
    func (e ValueError) Subtag() string
type Variant
    func ParseVariant(s string) (v Variant, err error)
    func (v Variant) String() string

Package files

common.go compact.go compose.go coverage.go language.go lookup.go match.go parse.go tables.go tags.go

Constants

CLDRVersion is the CLDR version from which the tables in this package are derived.

const CLDRVersion = "32"
const NumLanguages = 8798
const NumRegions = 358
const NumScripts = 261

Variables

AliasMap maps langIDs to their suggested replacements. Size: 772 bytes, 193 elements

var AliasMap = [193]FromTo{
    0:   {From: 0x82, To: 0x88},
    1:   {From: 0x187, To: 0x1ae},
    2:   {From: 0x1f3, To: 0x1e1},
    3:   {From: 0x1fb, To: 0x1bc},
    4:   {From: 0x208, To: 0x512},
    5:   {From: 0x20f, To: 0x20e},
    6:   {From: 0x310, To: 0x3dc},
    7:   {From: 0x347, To: 0x36f},
    8:   {From: 0x407, To: 0x432},
    9:   {From: 0x47a, To: 0x153},
    10:  {From: 0x490, To: 0x451},
    11:  {From: 0x4a2, To: 0x21},
    12:  {From: 0x53e, To: 0x544},
    13:  {From: 0x58f, To: 0x12d},
    14:  {From: 0x62b, To: 0x34},
    15:  {From: 0x62f, To: 0x14},
    16:  {From: 0x630, To: 0x1eb1},
    17:  {From: 0x651, To: 0x431},
    18:  {From: 0x662, To: 0x431},
    19:  {From: 0x6ed, To: 0x3a},
    20:  {From: 0x6f8, To: 0x1d7},
    21:  {From: 0x709, To: 0x3625},
    22:  {From: 0x73e, To: 0x21a1},
    23:  {From: 0x7b3, To: 0x56},
    24:  {From: 0x7b9, To: 0x299b},
    25:  {From: 0x7c5, To: 0x58},
    26:  {From: 0x7e6, To: 0x145},
    27:  {From: 0x80c, To: 0x5a},
    28:  {From: 0x815, To: 0x8d},
    29:  {From: 0x87e, To: 0x810},
    30:  {From: 0x8a8, To: 0x8b7},
    31:  {From: 0x8c3, To: 0xee3},
    32:  {From: 0x8fa, To: 0x1dc},
    33:  {From: 0x9ef, To: 0x331},
    34:  {From: 0xa36, To: 0x2c5},
    35:  {From: 0xa3d, To: 0xbf},
    36:  {From: 0xabe, To: 0x3322},
    37:  {From: 0xb38, To: 0x529},
    38:  {From: 0xb75, To: 0x265a},
    39:  {From: 0xb7e, To: 0xbc3},
    40:  {From: 0xb9b, To: 0x44e},
    41:  {From: 0xbbc, To: 0x4229},
    42:  {From: 0xbbf, To: 0x529},
    43:  {From: 0xbfe, To: 0x2da7},
    44:  {From: 0xc2e, To: 0x3181},
    45:  {From: 0xcb9, To: 0xf3},
    46:  {From: 0xd08, To: 0xfa},
    47:  {From: 0xdc8, To: 0x11a},
    48:  {From: 0xdd7, To: 0x32d},
    49:  {From: 0xdf8, To: 0xdfb},
    50:  {From: 0xdfe, To: 0x531},
    51:  {From: 0xe01, To: 0xdf3},
    52:  {From: 0xedf, To: 0x205a},
    53:  {From: 0xee9, To: 0x222e},
    54:  {From: 0xeee, To: 0x2e9a},
    55:  {From: 0xf39, To: 0x367},
    56:  {From: 0x10d0, To: 0x140},
    57:  {From: 0x1104, To: 0x2d0},
    58:  {From: 0x11a0, To: 0x1ec},
    59:  {From: 0x1279, To: 0x21},
    60:  {From: 0x1424, To: 0x15e},
    61:  {From: 0x1470, To: 0x14e},
    62:  {From: 0x151f, To: 0xd9b},
    63:  {From: 0x1523, To: 0x390},
    64:  {From: 0x1532, To: 0x19f},
    65:  {From: 0x1580, To: 0x210},
    66:  {From: 0x1583, To: 0x10d},
    67:  {From: 0x15a3, To: 0x3caf},
    68:  {From: 0x1630, To: 0x222e},
    69:  {From: 0x166a, To: 0x19b},
    70:  {From: 0x16c8, To: 0x136},
    71:  {From: 0x1700, To: 0x29f8},
    72:  {From: 0x1718, To: 0x194},
    73:  {From: 0x1727, To: 0xf3f},
    74:  {From: 0x177a, To: 0x178},
    75:  {From: 0x1809, To: 0x17b6},
    76:  {From: 0x1816, To: 0x18f3},
    77:  {From: 0x188a, To: 0x436},
    78:  {From: 0x1979, To: 0x1d01},
    79:  {From: 0x1a74, To: 0x2bb0},
    80:  {From: 0x1a8a, To: 0x1f8},
    81:  {From: 0x1b5a, To: 0x1fa},
    82:  {From: 0x1b86, To: 0x1515},
    83:  {From: 0x1d64, To: 0x2c9b},
    84:  {From: 0x2038, To: 0x37b1},
    85:  {From: 0x203d, To: 0x20dd},
    86:  {From: 0x2042, To: 0x2e00},
    87:  {From: 0x205a, To: 0x30b},
    88:  {From: 0x20e3, To: 0x274},
    89:  {From: 0x20ee, To: 0x263},
    90:  {From: 0x20f2, To: 0x22d},
    91:  {From: 0x20f9, To: 0x256},
    92:  {From: 0x210f, To: 0x21eb},
    93:  {From: 0x2135, To: 0x27d},
    94:  {From: 0x2160, To: 0x913},
    95:  {From: 0x2199, To: 0x121},
    96:  {From: 0x21ce, To: 0x1561},
    97:  {From: 0x21e6, To: 0x504},
    98:  {From: 0x21f4, To: 0x49f},
    99:  {From: 0x21fb, To: 0x269},
    100: {From: 0x222d, To: 0x121},
    101: {From: 0x2237, To: 0x121},
    102: {From: 0x2248, To: 0x217d},
    103: {From: 0x2262, To: 0x92a},
    104: {From: 0x2316, To: 0x3226},
    105: {From: 0x236a, To: 0x2835},
    106: {From: 0x2382, To: 0x3365},
    107: {From: 0x2472, To: 0x2c7},
    108: {From: 0x24e4, To: 0x2ff},
    109: {From: 0x24f0, To: 0x2fa},
    110: {From: 0x24fa, To: 0x31f},
    111: {From: 0x2550, To: 0xb5b},
    112: {From: 0x25a9, To: 0xe2},
    113: {From: 0x263e, To: 0x2d0},
    114: {From: 0x26c9, To: 0x26b4},
    115: {From: 0x26f9, To: 0x3c8},
    116: {From: 0x2727, To: 0x3caf},
    117: {From: 0x2755, To: 0x6a4},
    118: {From: 0x2765, To: 0x26b4},
    119: {From: 0x2789, To: 0x4358},
    120: {From: 0x27c9, To: 0x2001},
    121: {From: 0x28ea, To: 0x27b1},
    122: {From: 0x28ef, To: 0x2837},
    123: {From: 0x28fe, To: 0xaa5},
    124: {From: 0x2914, To: 0x351},
    125: {From: 0x2986, To: 0x2da7},
    126: {From: 0x29f0, To: 0x96b},
    127: {From: 0x2b1a, To: 0x38d},
    128: {From: 0x2bfc, To: 0x395},
    129: {From: 0x2c3f, To: 0x3caf},
    130: {From: 0x2ce1, To: 0x2201},
    131: {From: 0x2cfc, To: 0x3be},
    132: {From: 0x2d13, To: 0x597},
    133: {From: 0x2d47, To: 0x148},
    134: {From: 0x2d48, To: 0x148},
    135: {From: 0x2dff, To: 0x2f1},
    136: {From: 0x2e08, To: 0x19cc},
    137: {From: 0x2e10, To: 0xc45},
    138: {From: 0x2e1a, To: 0x2d95},
    139: {From: 0x2e21, To: 0x292},
    140: {From: 0x2e54, To: 0x7d},
    141: {From: 0x2e65, To: 0x2282},
    142: {From: 0x2e97, To: 0x1a4},
    143: {From: 0x2ea0, To: 0x2e9b},
    144: {From: 0x2eef, To: 0x2ed7},
    145: {From: 0x3193, To: 0x3c4},
    146: {From: 0x3366, To: 0x338e},
    147: {From: 0x342a, To: 0x3dc},
    148: {From: 0x34ee, To: 0x18d0},
    149: {From: 0x35c8, To: 0x2c9b},
    150: {From: 0x35e6, To: 0x412},
    151: {From: 0x35f5, To: 0x24b},
    152: {From: 0x360d, To: 0x1dc},
    153: {From: 0x3658, To: 0x246},
    154: {From: 0x3676, To: 0x3f4},
    155: {From: 0x36fd, To: 0x445},
    156: {From: 0x3747, To: 0x3b42},
    157: {From: 0x37c0, To: 0x121},
    158: {From: 0x3816, To: 0x38f2},
    159: {From: 0x382a, To: 0x2b48},
    160: {From: 0x382b, To: 0x2c9b},
    161: {From: 0x382f, To: 0xa9},
    162: {From: 0x3832, To: 0x3228},
    163: {From: 0x386c, To: 0x39a6},
    164: {From: 0x3892, To: 0x3fc0},
    165: {From: 0x38a0, To: 0x45f},
    166: {From: 0x38a5, To: 0x39d7},
    167: {From: 0x38b4, To: 0x1fa4},
    168: {From: 0x38b5, To: 0x2e9a},
    169: {From: 0x38fa, To: 0x38f1},
    170: {From: 0x395c, To: 0x47e},
    171: {From: 0x3b4e, To: 0xd91},
    172: {From: 0x3b78, To: 0x137},
    173: {From: 0x3c99, To: 0x4bc},
    174: {From: 0x3fbd, To: 0x100},
    175: {From: 0x4208, To: 0xa91},
    176: {From: 0x42be, To: 0x573},
    177: {From: 0x42f9, To: 0x3f60},
    178: {From: 0x4378, To: 0x25a},
    179: {From: 0x43b8, To: 0xe6c},
    180: {From: 0x43cd, To: 0x10f},
    181: {From: 0x43d4, To: 0x4848},
    182: {From: 0x44af, To: 0x3322},
    183: {From: 0x44e3, To: 0x512},
    184: {From: 0x45ca, To: 0x2409},
    185: {From: 0x45dd, To: 0x26dc},
    186: {From: 0x4610, To: 0x48ae},
    187: {From: 0x46ae, To: 0x46a0},
    188: {From: 0x473e, To: 0x4745},
    189: {From: 0x4817, To: 0x3503},
    190: {From: 0x483b, To: 0x208b},
    191: {From: 0x4916, To: 0x31f},
    192: {From: 0x49a7, To: 0x523},
}

Size: 193 bytes, 193 elements

var AliasTypes = [193]AliasType{

    1, 0, 0, 0, 0, 0, 0, 1, 2, 2, 0, 1, 0, 0, 0, 0,
    1, 2, 1, 1, 2, 0, 0, 1, 0, 1, 2, 1, 1, 0, 0, 0,
    0, 2, 1, 1, 0, 2, 0, 0, 1, 0, 1, 0, 0, 1, 2, 1,
    1, 1, 1, 0, 0, 0, 0, 2, 1, 1, 1, 1, 2, 1, 0, 1,

    1, 2, 2, 0, 0, 1, 2, 0, 1, 0, 1, 1, 1, 1, 0, 0,
    2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 2, 2, 0,
    1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1,

    1, 0, 0, 1, 0, 2, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
    0, 1, 1, 2, 0, 0, 2, 0, 0, 1, 1, 1, 0, 0, 0, 0,
    0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 2, 0,
    0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1,

    1,
}

ErrDuplicateKey is returned when a tag contains the same key twice with different values in the -u section.

var ErrDuplicateKey = errors.New("language: different values for same key in -u extension")

ErrMissingLikelyTagsData indicates no information was available to compute likely values of missing tags.

var ErrMissingLikelyTagsData = errors.New("missing likely tags data")

ErrSyntax is returned by any of the parsing functions when the input is not well-formed, according to BCP 47. TODO: return the position at which the syntax error occurred?

var ErrSyntax = errors.New("language: tag is not well-formed")

func ParseExtension

func ParseExtension(s string) (ext string, err error)

ParseExtension parses s as an extension and returns it on success.

type AliasType

AliasType is the type of an alias in AliasMap.

type AliasType int8
const (
    Deprecated AliasType = iota
    Macro
    Legacy

    AliasTypeUnknown AliasType = -1
)

type Builder

A Builder allows constructing a Tag from individual components. Its main user is Compose in the top-level language package.

type Builder struct {
    Tag Tag
    // contains filtered or unexported fields
}

func (*Builder) AddExt

func (b *Builder) AddExt(e string)

AddExt adds extension e to the tag. e must be a valid extension as returned by Tag.Extension. If the extension already exists, it will be discarded, except for a -u extension, where non-existing key-type pairs will added.

func (*Builder) AddVariant

func (b *Builder) AddVariant(v ...string)

AddVariant adds any number of variants.

func (*Builder) ClearExtensions

func (b *Builder) ClearExtensions()

ClearExtensions removes any extensions previously added, including those copied from a Tag in SetTag.

func (*Builder) ClearVariants

func (b *Builder) ClearVariants()

ClearVariants removes any variants previously added, including those copied from a Tag in SetTag.

func (*Builder) Make

func (b *Builder) Make() Tag

Make returns a new Tag from the current settings.

func (*Builder) SetExt

func (b *Builder) SetExt(e string)

SetExt sets the extension e to the tag. e must be a valid extension as returned by Tag.Extension. If the extension already exists, it will be overwritten, except for a -u extension, where the individual key-type pairs will be set.

func (*Builder) SetTag

func (b *Builder) SetTag(t Tag)

SetTag copies all the settings from a given Tag. Any previously set values are discarded.

type CompactCoreInfo

CompactCoreInfo is a compact integer with the three core tags encoded.

type CompactCoreInfo uint32

func GetCompactCore

func GetCompactCore(t Tag) (cci CompactCoreInfo, ok bool)

GetCompactCore generates a uint32 value that is guaranteed to be unique for different language, region, and script values.

func (CompactCoreInfo) Tag

func (c CompactCoreInfo) Tag() Tag

Tag generates a tag from c.

type FromTo

type FromTo struct {
    From uint16
    To   uint16
}

type Language

type Language uint16

func BaseLanguages

func BaseLanguages() []Language

BaseLanguages returns the list of all supported base languages. It generates the list by traversing the internal structures.

func MustParseBase

func MustParseBase(s string) Language

MustParseBase is like ParseBase, but panics if the given base cannot be parsed. It simplifies safe initialization of Base values.

func ParseBase

func ParseBase(s string) (l Language, err error)

ParseBase parses a 2- or 3-letter ISO 639 code. It returns a ValueError if s is a well-formed but unknown language identifier or another error if another error occurred.

func (Language) Canonicalize

func (id Language) Canonicalize() (Language, AliasType)

func (Language) ISO3

func (b Language) ISO3() string

ISO3 returns the ISO 639-3 language code.

func (Language) IsPrivateUse

func (b Language) IsPrivateUse() bool

IsPrivateUse reports whether this language code is reserved for private use.

func (Language) String

func (b Language) String() string

String returns the BCP 47 representation of the langID. Use b as variable name, instead of id, to ensure the variable used is consistent with that of Base in which this type is embedded.

func (Language) StringToBuf

func (id Language) StringToBuf(b []byte) int

StringToBuf writes the string to b and returns the number of bytes written. cap(b) must be >= 3.

func (Language) SuppressScript

func (b Language) SuppressScript() Script

SuppressScript returns the script marked as SuppressScript in the IANA language tag repository, or 0 if there is no such script.

type Region

type Region uint16

func EncodeM49

func EncodeM49(r int) (Region, error)

EncodeM49 returns the Region for the given UN M.49 code. It returns an error if r is not a valid code.

func MustParseRegion

func MustParseRegion(s string) Region

MustParseRegion is like ParseRegion, but panics if the given region cannot be parsed. It simplifies safe initialization of Region values.

func ParseRegion

func ParseRegion(s string) (r Region, err error)

ParseRegion parses a 2- or 3-letter ISO 3166-1 or a UN M.49 code. It returns a ValueError if s is a well-formed but unknown region identifier or another error if another error occurred.

func (Region) Canonicalize

func (r Region) Canonicalize() Region

Canonicalize returns the region or a possible replacement if the region is deprecated. It will not return a replacement for deprecated regions that are split into multiple regions.

func (Region) Contains

func (r Region) Contains(c Region) bool

Contains returns whether Region c is contained by Region r. It returns true if c == r.

func (Region) ISO3

func (r Region) ISO3() string

ISO3 returns the 3-letter ISO code of r. Note that not all regions have a 3-letter ISO code. In such cases this method returns "ZZZ".

func (Region) IsCountry

func (r Region) IsCountry() bool

IsCountry returns whether this region is a country or autonomous area. This includes non-standard definitions from CLDR.

func (Region) IsGroup

func (r Region) IsGroup() bool

IsGroup returns whether this region defines a collection of regions. This includes non-standard definitions from CLDR.

func (Region) IsPrivateUse

func (r Region) IsPrivateUse() bool

IsPrivateUse reports whether r has the ISO 3166 User-assigned status. This may include private-use tags that are assigned by CLDR and used in this implementation. So IsPrivateUse and IsCountry can be simultaneously true.

func (Region) M49

func (r Region) M49() int

M49 returns the UN M.49 encoding of r, or 0 if this encoding is not defined for r.

func (Region) String

func (r Region) String() string

String returns the BCP 47 representation for the region. It returns "ZZ" for an unspecified region.

func (Region) TLD

func (r Region) TLD() (Region, error)

TLD returns the country code top-level domain (ccTLD). UK is returned for GB. In all other cases it returns either the region itself or an error.

This method may return an error for a region for which there exists a canonical form with a ccTLD. To get that ccTLD canonicalize r first. The region will already be canonicalized it was obtained from a Tag that was obtained using any of the default methods.

type Script

type Script uint16

func MustParseScript

func MustParseScript(s string) Script

MustParseScript is like ParseScript, but panics if the given script cannot be parsed. It simplifies safe initialization of Script values.

func ParseScript

func ParseScript(s string) (scr Script, err error)

ParseScript parses a 4-letter ISO 15924 code. It returns a ValueError if s is a well-formed but unknown script identifier or another error if another error occurred.

func (Script) IsPrivateUse

func (s Script) IsPrivateUse() bool

IsPrivateUse reports whether this script code is reserved for private use.

func (Script) String

func (s Script) String() string

String returns the script code in title case. It returns "Zzzz" for an unspecified script.

type Tag

Tag represents a BCP 47 language tag. It is used to specify an instance of a specific language or locale. All language tag values are guaranteed to be well-formed. The zero value of Tag is Und.

type Tag struct {
    LangID   Language
    RegionID Region
    // TODO: we will soon run out of positions for ScriptID. Idea: instead of
    // storing lang, region, and ScriptID codes, store only the compact index and
    // have a lookup table from this code to its expansion. This greatly speeds
    // up table lookup, speed up common variant cases.
    // This will also immediately free up 3 extra bytes. Also, the pVariant
    // field can now be moved to the lookup table, as the compact index uniquely
    // determines the offset of a possible variant.
    ScriptID Script
    // contains filtered or unexported fields
}

Und is the root language.

var Und Tag

func Make

func Make(s string) Tag

Make is a convenience wrapper for Parse that omits the error. In case of an error, a sensible default is returned.

func MustParse

func MustParse(s string) Tag

MustParse is like Parse, but panics if the given BCP 47 tag cannot be parsed. It simplifies safe initialization of Tag values.

func Parse

func Parse(s string) (t Tag, err error)

Parse parses the given BCP 47 string and returns a valid Tag. If parsing failed it returns an error and any part of the tag that could be parsed. If parsing succeeded but an unknown value was found, it returns ValueError. The Tag returned in this case is just stripped of the unknown value. All other values are preserved. It accepts tags in the BCP 47 format and extensions to this standard defined in https://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers.

func (Tag) Extension

func (t Tag) Extension(x byte) (ext string, ok bool)

Extension returns the extension of type x for tag t. It will return false for ok if t does not have the requested extension. The returned extension will be invalid in this case.

func (Tag) Extensions

func (t Tag) Extensions() []string

Extensions returns all extensions of t.

func (Tag) HasExtensions

func (t Tag) HasExtensions() bool

HasExtensions reports whether t has extensions.

func (Tag) HasString

func (t Tag) HasString() bool

HasString reports whether this tag defines more than just the raw components.

func (Tag) HasVariants

func (t Tag) HasVariants() bool

HasVariants reports whether t has variants.

func (Tag) IsPrivateUse

func (t Tag) IsPrivateUse() bool

IsPrivateUse reports whether the Tag consists solely of an IsPrivateUse use tag.

func (Tag) IsRoot

func (t Tag) IsRoot() bool

IsRoot returns true if t is equal to language "und".

func (Tag) MarshalText

func (t Tag) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Tag) Maximize

func (t Tag) Maximize() (Tag, error)

Maximize returns a new tag with missing tags filled in.

func (Tag) Parent

func (t Tag) Parent() Tag

Parent returns the CLDR parent of t. In CLDR, missing fields in data for a specific language are substituted with fields from the parent language. The parent for a language may change for newer versions of CLDR.

func (Tag) Raw

func (t Tag) Raw() (b Language, s Script, r Region)

Raw returns the raw base language, script and region, without making an attempt to infer their values. TODO: consider removing

func (*Tag) RemakeString

func (t *Tag) RemakeString()

RemakeString is used to update t.str in case lang, script or region changed. It is assumed that pExt and pVariant still point to the start of the respective parts.

func (Tag) SetTypeForKey

func (t Tag) SetTypeForKey(key, value string) (Tag, error)

SetTypeForKey returns a new Tag with the key set to type, where key and type are of the allowed values defined for the Unicode locale extension ('u') in https://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers. An empty value removes an existing pair with the same key.

func (Tag) String

func (t Tag) String() string

String returns the canonical string representation of the language tag.

func (Tag) TypeForKey

func (t Tag) TypeForKey(key string) string

TypeForKey returns the type associated with the given key, where key and type are of the allowed values defined for the Unicode locale extension ('u') in https://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers. TypeForKey will traverse the inheritance chain to get the correct value.

If there are multiple types associated with a key, only the first will be returned. If there is no type associated with a key, it returns the empty string.

func (*Tag) UnmarshalText

func (t *Tag) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Tag) VariantOrPrivateUseTags

func (t Tag) VariantOrPrivateUseTags() string

VariantOrPrivateUseTags returns variants or private use tags.

func (Tag) Variants

func (t Tag) Variants() string

Variants returns the part of the tag holding all variants or the empty string if there are no variants defined.

type ValueError

ValueError is returned by any of the parsing functions when the input is well-formed but the respective subtag is not recognized as a valid value.

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

func NewValueError

func NewValueError(tag []byte) ValueError

NewValueError creates a new ValueError.

func (ValueError) Error

func (e ValueError) Error() string

Error implements the error interface.

func (ValueError) Subtag

func (e ValueError) Subtag() string

Subtag returns the subtag for which the error occurred.

type Variant

Variant represents a registered variant of a language as defined by BCP 47.

type Variant struct {
    ID uint8
    // contains filtered or unexported fields
}

func ParseVariant

func ParseVariant(s string) (v Variant, err error)

ParseVariant parses and returns a Variant. An error is returned if s is not a valid variant.

func (Variant) String

func (v Variant) String() string

String returns the string representation of the variant.

Subdirectories

Name Synopsis
..