text: golang.org/x/text/internal/language Index | Files | Directories

package language

import "golang.org/x/text/internal/language"

Index

Package Files

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

Constants

const CLDRVersion = "32"

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

const NumLanguages = 8665
const NumRegions = 357
const NumScripts = 242

Variables

var AliasMap = [164]FromTo{ /* 164 elements not displayed */

}

AliasMap maps langIDs to their suggested replacements. Size: 656 bytes, 164 elements

var AliasTypes = [164]AliasType{ /* 164 elements not displayed */

}

Size: 164 bytes, 164 elements

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

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

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

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

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

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?

func ParseExtension Uses

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

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

type AliasType Uses

type AliasType int8

AliasType is the type of an alias in AliasMap.

const (
    Deprecated AliasType = iota
    Macro
    Legacy

    AliasTypeUnknown AliasType = -1
)

type Builder Uses

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

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

func (*Builder) AddExt Uses

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 Uses

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

AddVariant adds any number of variants.

func (*Builder) ClearExtensions Uses

func (b *Builder) ClearExtensions()

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

func (*Builder) ClearVariants Uses

func (b *Builder) ClearVariants()

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

func (*Builder) Make Uses

func (b *Builder) Make() Tag

Make returns a new Tag from the current settings.

func (*Builder) SetExt Uses

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 Uses

func (b *Builder) SetTag(t Tag)

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

type CompactCoreInfo Uses

type CompactCoreInfo uint32

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

func GetCompactCore Uses

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 Uses

func (c CompactCoreInfo) Tag() Tag

Tag generates a tag from c.

type FromTo Uses

type FromTo struct {
    From uint16
    To   uint16
}

type Language Uses

type Language uint16

func BaseLanguages Uses

func BaseLanguages() []Language

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

func MustParseBase Uses

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 Uses

func ParseBase(s string) (Language, 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 Uses

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

func (Language) ISO3 Uses

func (b Language) ISO3() string

ISO3 returns the ISO 639-3 language code.

func (Language) IsPrivateUse Uses

func (b Language) IsPrivateUse() bool

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

func (Language) String Uses

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 Uses

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 Uses

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 Uses

type Region uint16

func EncodeM49 Uses

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 Uses

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 Uses

func ParseRegion(s string) (Region, 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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (r Region) String() string

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

func (Region) TLD Uses

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 Uses

type Script uint8

func MustParseScript Uses

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 Uses

func ParseScript(s string) (Script, 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 Uses

func (s Script) IsPrivateUse() bool

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

func (Script) String Uses

func (s Script) String() string

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

type Tag Uses

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
}

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.

var Und Tag

Und is the root language.

func Make Uses

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 Uses

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 Uses

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 http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers.

func (Tag) Extension Uses

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 Uses

func (t Tag) Extensions() []string

Extensions returns all extensions of t.

func (Tag) HasExtensions Uses

func (t Tag) HasExtensions() bool

HasExtensions reports whether t has extensions.

func (Tag) HasString Uses

func (t Tag) HasString() bool

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

func (Tag) HasVariants Uses

func (t Tag) HasVariants() bool

HasVariants reports whether t has variants.

func (Tag) IsPrivateUse Uses

func (t Tag) IsPrivateUse() bool

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

func (Tag) IsRoot Uses

func (t Tag) IsRoot() bool

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

func (Tag) MarshalText Uses

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

MarshalText implements encoding.TextMarshaler.

func (Tag) Maximize Uses

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

Maximize returns a new tag with missing tags filled in.

func (Tag) Parent Uses

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 Uses

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 Uses

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 Uses

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 http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers. An empty value removes an existing pair with the same key.

func (Tag) String Uses

func (t Tag) String() string

String returns the canonical string representation of the language tag.

func (Tag) TypeForKey Uses

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 http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers. TypeForKey will traverse the inheritance chain to get the correct value.

func (*Tag) UnmarshalText Uses

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Tag) VariantOrPrivateUseTags Uses

func (t Tag) VariantOrPrivateUseTags() string

VariantOrPrivateUseTags returns variants or private use tags.

func (Tag) Variants Uses

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 Uses

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

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.

func NewValueError Uses

func NewValueError(tag []byte) ValueError

NewValueError creates a new ValueError.

func (ValueError) Error Uses

func (e ValueError) Error() string

Error implements the error interface.

func (ValueError) Subtag Uses

func (e ValueError) Subtag() string

Subtag returns the subtag for which the error occurred.

type Variant Uses

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

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

func ParseVariant Uses

func ParseVariant(s string) (Variant, error)

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

func (Variant) String Uses

func (v Variant) String() string

String returns the string representation of the variant.

Directories

PathSynopsis
compactPackage compact defines a compact representation of language tags.

Package language imports 7 packages (graph) and is imported by 2 packages. Updated 2018-06-17. Refresh now. Tools for package owners.