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

package compact

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

Package compact defines a compact representation of language tags.

Common language tags (at least all for which locale information is defined in CLDR) are assigned a unique index. Each Tag is associated with such an ID for selecting language-related resources (such as translations) as well as one for selecting regional defaults (currency, number formatting, etc.)

It may want to export this functionality at some point, but at this point this is only available for use within x/text.


Package Files

compact.go language.go parents.go tables.go tags.go


const CLDRVersion = "32"

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

const NumCompactTags = 775

NumCompactTags is the number of common tags. The maximum tag is NumCompactTags-1.

type ID Uses

type ID uint16

ID is an integer identifying a single tag.

func FromTag Uses

func FromTag(t language.Tag) (id ID, exact bool)

FromTag reports closest matching ID for an internal language Tag.

func LanguageID Uses

func LanguageID(t Tag) (id ID, exact bool)

LanguageID returns an index, where 0 <= index < NumCompactTags, for tags for which data exists in the text repository.The index will change over time and should not be stored in persistent storage. If t does not match a compact index, exact will be false and the compact index will be returned for the first match after repeatedly taking the Parent of t.

func RegionalID Uses

func RegionalID(t Tag) (id ID, exact bool)

RegionalID returns the ID for the regional variant of this tag. This index is used to indicate region-specific overrides, such as default currency, default calendar and week data, default time cycle, and default measurement system and unit preferences.

For instance, the tag en-GB-u-rg-uszzzz specifies British English with US settings for currency, number formatting, etc. The CompactIndex for this tag will be that for en-GB, while the RegionalID will be the one corresponding to en-US.

func (ID) Parent Uses

func (id ID) Parent() ID

Parent returns the ID of the parent or the root ID if id is already the root.

func (ID) Tag Uses

func (id ID) Tag() language.Tag

Tag converts id to an internal language Tag.

type Tag Uses

type Tag struct {
    // 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.

var (
    Und Tag = Tag{}

    Afrikaans            Tag = Tag{language: afIndex, locale: afIndex}
    Amharic              Tag = Tag{language: amIndex, locale: amIndex}
    Arabic               Tag = Tag{language: arIndex, locale: arIndex}
    ModernStandardArabic Tag = Tag{language: ar001Index, locale: ar001Index}
    Azerbaijani          Tag = Tag{language: azIndex, locale: azIndex}
    Bulgarian            Tag = Tag{language: bgIndex, locale: bgIndex}
    Bengali              Tag = Tag{language: bnIndex, locale: bnIndex}
    Catalan              Tag = Tag{language: caIndex, locale: caIndex}
    Czech                Tag = Tag{language: csIndex, locale: csIndex}
    Danish               Tag = Tag{language: daIndex, locale: daIndex}
    German               Tag = Tag{language: deIndex, locale: deIndex}
    Greek                Tag = Tag{language: elIndex, locale: elIndex}
    English              Tag = Tag{language: enIndex, locale: enIndex}
    AmericanEnglish      Tag = Tag{language: enUSIndex, locale: enUSIndex}
    BritishEnglish       Tag = Tag{language: enGBIndex, locale: enGBIndex}
    Spanish              Tag = Tag{language: esIndex, locale: esIndex}
    EuropeanSpanish      Tag = Tag{language: esESIndex, locale: esESIndex}
    LatinAmericanSpanish Tag = Tag{language: es419Index, locale: es419Index}
    Estonian             Tag = Tag{language: etIndex, locale: etIndex}
    Persian              Tag = Tag{language: faIndex, locale: faIndex}
    Finnish              Tag = Tag{language: fiIndex, locale: fiIndex}
    Filipino             Tag = Tag{language: filIndex, locale: filIndex}
    French               Tag = Tag{language: frIndex, locale: frIndex}
    CanadianFrench       Tag = Tag{language: frCAIndex, locale: frCAIndex}
    Gujarati             Tag = Tag{language: guIndex, locale: guIndex}
    Hebrew               Tag = Tag{language: heIndex, locale: heIndex}
    Hindi                Tag = Tag{language: hiIndex, locale: hiIndex}
    Croatian             Tag = Tag{language: hrIndex, locale: hrIndex}
    Hungarian            Tag = Tag{language: huIndex, locale: huIndex}
    Armenian             Tag = Tag{language: hyIndex, locale: hyIndex}
    Indonesian           Tag = Tag{language: idIndex, locale: idIndex}
    Icelandic            Tag = Tag{language: isIndex, locale: isIndex}
    Italian              Tag = Tag{language: itIndex, locale: itIndex}
    Japanese             Tag = Tag{language: jaIndex, locale: jaIndex}
    Georgian             Tag = Tag{language: kaIndex, locale: kaIndex}
    Kazakh               Tag = Tag{language: kkIndex, locale: kkIndex}
    Khmer                Tag = Tag{language: kmIndex, locale: kmIndex}
    Kannada              Tag = Tag{language: knIndex, locale: knIndex}
    Korean               Tag = Tag{language: koIndex, locale: koIndex}
    Kirghiz              Tag = Tag{language: kyIndex, locale: kyIndex}
    Lao                  Tag = Tag{language: loIndex, locale: loIndex}
    Lithuanian           Tag = Tag{language: ltIndex, locale: ltIndex}
    Latvian              Tag = Tag{language: lvIndex, locale: lvIndex}
    Macedonian           Tag = Tag{language: mkIndex, locale: mkIndex}
    Malayalam            Tag = Tag{language: mlIndex, locale: mlIndex}
    Mongolian            Tag = Tag{language: mnIndex, locale: mnIndex}
    Marathi              Tag = Tag{language: mrIndex, locale: mrIndex}
    Malay                Tag = Tag{language: msIndex, locale: msIndex}
    Burmese              Tag = Tag{language: myIndex, locale: myIndex}
    Nepali               Tag = Tag{language: neIndex, locale: neIndex}
    Dutch                Tag = Tag{language: nlIndex, locale: nlIndex}
    Norwegian            Tag = Tag{language: noIndex, locale: noIndex}
    Punjabi              Tag = Tag{language: paIndex, locale: paIndex}
    Polish               Tag = Tag{language: plIndex, locale: plIndex}
    Portuguese           Tag = Tag{language: ptIndex, locale: ptIndex}
    BrazilianPortuguese  Tag = Tag{language: ptBRIndex, locale: ptBRIndex}
    EuropeanPortuguese   Tag = Tag{language: ptPTIndex, locale: ptPTIndex}
    Romanian             Tag = Tag{language: roIndex, locale: roIndex}
    Russian              Tag = Tag{language: ruIndex, locale: ruIndex}
    Sinhala              Tag = Tag{language: siIndex, locale: siIndex}
    Slovak               Tag = Tag{language: skIndex, locale: skIndex}
    Slovenian            Tag = Tag{language: slIndex, locale: slIndex}
    Albanian             Tag = Tag{language: sqIndex, locale: sqIndex}
    Serbian              Tag = Tag{language: srIndex, locale: srIndex}
    SerbianLatin         Tag = Tag{language: srLatnIndex, locale: srLatnIndex}
    Swedish              Tag = Tag{language: svIndex, locale: svIndex}
    Swahili              Tag = Tag{language: swIndex, locale: swIndex}
    Tamil                Tag = Tag{language: taIndex, locale: taIndex}
    Telugu               Tag = Tag{language: teIndex, locale: teIndex}
    Thai                 Tag = Tag{language: thIndex, locale: thIndex}
    Turkish              Tag = Tag{language: trIndex, locale: trIndex}
    Ukrainian            Tag = Tag{language: ukIndex, locale: ukIndex}
    Urdu                 Tag = Tag{language: urIndex, locale: urIndex}
    Uzbek                Tag = Tag{language: uzIndex, locale: uzIndex}
    Vietnamese           Tag = Tag{language: viIndex, locale: viIndex}
    Chinese              Tag = Tag{language: zhIndex, locale: zhIndex}
    SimplifiedChinese    Tag = Tag{language: zhHansIndex, locale: zhHansIndex}
    TraditionalChinese   Tag = Tag{language: zhHantIndex, locale: zhHantIndex}
    Zulu                 Tag = Tag{language: zuIndex, locale: zuIndex}

func Make Uses

func Make(t language.Tag) (tag Tag)

Make a compact Tag from a fully specified internal language Tag.

func (*Tag) IsCompact Uses

func (t *Tag) IsCompact() bool

IsCompact reports whether this tag is fully defined in terms of ID.

func (Tag) IsRoot Uses

func (t Tag) IsRoot() bool

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

func (Tag) LanguageTag Uses

func (t Tag) LanguageTag() Tag

LanguageTag returns t stripped of regional variant indicators.

At the moment this means it is stripped of a regional and variant subtag "rg" and "va" in the "u" extension.

func (Tag) MayHaveExtensions Uses

func (t Tag) MayHaveExtensions() bool

MayHaveExtensions reports whether a tag may have extensions. If it returns false it is guaranteed the tag does not have them.

func (Tag) MayHaveVariants Uses

func (t Tag) MayHaveVariants() bool

MayHaveVariants reports whether a tag may have variants. If it returns false it is guaranteed the tag does not have variants.

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) RegionalTag Uses

func (t Tag) RegionalTag() Tag

RegionalTag returns the regional variant of the tag.

At the moment this means that the region is set from the regional subtag "rg" in the "u" extension.

func (Tag) Tag Uses

func (t Tag) Tag() language.Tag

Tag returns an internal language Tag version of this tag.

Package compact imports 3 packages (graph) and is imported by 6 packages. Updated 2018-06-17. Refresh now. Tools for package owners.