Documentation

Overview

    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.

    Index

    Constants

    View Source
    const CLDRVersion = "32"

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

      View Source
      const NumCompactTags = 775

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

        Variables

        This section is empty.

        Functions

        This section is empty.

        Types

        type ID

        type ID uint16

          ID is an integer identifying a single tag.

          func FromTag

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

            FromTag reports closest matching ID for an internal language Tag.

            func LanguageID

            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

              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

                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

                  func (id ID) Tag() language.Tag

                    Tag converts id to an internal language Tag.

                    type Tag

                    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{/* contains filtered or unexported fields */}
                      	Amharic              Tag = Tag{/* contains filtered or unexported fields */}
                      	Arabic               Tag = Tag{/* contains filtered or unexported fields */}
                      	ModernStandardArabic Tag = Tag{/* contains filtered or unexported fields */}
                      	Azerbaijani          Tag = Tag{/* contains filtered or unexported fields */}
                      	Bulgarian            Tag = Tag{/* contains filtered or unexported fields */}
                      	Bengali              Tag = Tag{/* contains filtered or unexported fields */}
                      	Catalan              Tag = Tag{/* contains filtered or unexported fields */}
                      	Czech                Tag = Tag{/* contains filtered or unexported fields */}
                      	Danish               Tag = Tag{/* contains filtered or unexported fields */}
                      	German               Tag = Tag{/* contains filtered or unexported fields */}
                      	Greek                Tag = Tag{/* contains filtered or unexported fields */}
                      	English              Tag = Tag{/* contains filtered or unexported fields */}
                      	AmericanEnglish      Tag = Tag{/* contains filtered or unexported fields */}
                      	BritishEnglish       Tag = Tag{/* contains filtered or unexported fields */}
                      	Spanish              Tag = Tag{/* contains filtered or unexported fields */}
                      	EuropeanSpanish      Tag = Tag{/* contains filtered or unexported fields */}
                      	LatinAmericanSpanish Tag = Tag{/* contains filtered or unexported fields */}
                      	Estonian             Tag = Tag{/* contains filtered or unexported fields */}
                      	Persian              Tag = Tag{/* contains filtered or unexported fields */}
                      	Finnish              Tag = Tag{/* contains filtered or unexported fields */}
                      	Filipino             Tag = Tag{/* contains filtered or unexported fields */}
                      	French               Tag = Tag{/* contains filtered or unexported fields */}
                      	CanadianFrench       Tag = Tag{/* contains filtered or unexported fields */}
                      	Gujarati             Tag = Tag{/* contains filtered or unexported fields */}
                      	Hebrew               Tag = Tag{/* contains filtered or unexported fields */}
                      	Hindi                Tag = Tag{/* contains filtered or unexported fields */}
                      	Croatian             Tag = Tag{/* contains filtered or unexported fields */}
                      	Hungarian            Tag = Tag{/* contains filtered or unexported fields */}
                      	Armenian             Tag = Tag{/* contains filtered or unexported fields */}
                      	Indonesian           Tag = Tag{/* contains filtered or unexported fields */}
                      	Icelandic            Tag = Tag{/* contains filtered or unexported fields */}
                      	Italian              Tag = Tag{/* contains filtered or unexported fields */}
                      	Japanese             Tag = Tag{/* contains filtered or unexported fields */}
                      	Georgian             Tag = Tag{/* contains filtered or unexported fields */}
                      	Kazakh               Tag = Tag{/* contains filtered or unexported fields */}
                      	Khmer                Tag = Tag{/* contains filtered or unexported fields */}
                      	Kannada              Tag = Tag{/* contains filtered or unexported fields */}
                      	Korean               Tag = Tag{/* contains filtered or unexported fields */}
                      	Kirghiz              Tag = Tag{/* contains filtered or unexported fields */}
                      	Lao                  Tag = Tag{/* contains filtered or unexported fields */}
                      	Lithuanian           Tag = Tag{/* contains filtered or unexported fields */}
                      	Latvian              Tag = Tag{/* contains filtered or unexported fields */}
                      	Macedonian           Tag = Tag{/* contains filtered or unexported fields */}
                      	Malayalam            Tag = Tag{/* contains filtered or unexported fields */}
                      	Mongolian            Tag = Tag{/* contains filtered or unexported fields */}
                      	Marathi              Tag = Tag{/* contains filtered or unexported fields */}
                      	Malay                Tag = Tag{/* contains filtered or unexported fields */}
                      	Burmese              Tag = Tag{/* contains filtered or unexported fields */}
                      	Nepali               Tag = Tag{/* contains filtered or unexported fields */}
                      	Dutch                Tag = Tag{/* contains filtered or unexported fields */}
                      	Norwegian            Tag = Tag{/* contains filtered or unexported fields */}
                      	Punjabi              Tag = Tag{/* contains filtered or unexported fields */}
                      	Polish               Tag = Tag{/* contains filtered or unexported fields */}
                      	Portuguese           Tag = Tag{/* contains filtered or unexported fields */}
                      	BrazilianPortuguese  Tag = Tag{/* contains filtered or unexported fields */}
                      	EuropeanPortuguese   Tag = Tag{/* contains filtered or unexported fields */}
                      	Romanian             Tag = Tag{/* contains filtered or unexported fields */}
                      	Russian              Tag = Tag{/* contains filtered or unexported fields */}
                      	Sinhala              Tag = Tag{/* contains filtered or unexported fields */}
                      	Slovak               Tag = Tag{/* contains filtered or unexported fields */}
                      	Slovenian            Tag = Tag{/* contains filtered or unexported fields */}
                      	Albanian             Tag = Tag{/* contains filtered or unexported fields */}
                      	Serbian              Tag = Tag{/* contains filtered or unexported fields */}
                      	SerbianLatin         Tag = Tag{/* contains filtered or unexported fields */}
                      	Swedish              Tag = Tag{/* contains filtered or unexported fields */}
                      	Swahili              Tag = Tag{/* contains filtered or unexported fields */}
                      	Tamil                Tag = Tag{/* contains filtered or unexported fields */}
                      	Telugu               Tag = Tag{/* contains filtered or unexported fields */}
                      	Thai                 Tag = Tag{/* contains filtered or unexported fields */}
                      	Turkish              Tag = Tag{/* contains filtered or unexported fields */}
                      	Ukrainian            Tag = Tag{/* contains filtered or unexported fields */}
                      	Urdu                 Tag = Tag{/* contains filtered or unexported fields */}
                      	Uzbek                Tag = Tag{/* contains filtered or unexported fields */}
                      	Vietnamese           Tag = Tag{/* contains filtered or unexported fields */}
                      	Chinese              Tag = Tag{/* contains filtered or unexported fields */}
                      	SimplifiedChinese    Tag = Tag{/* contains filtered or unexported fields */}
                      	TraditionalChinese   Tag = Tag{/* contains filtered or unexported fields */}
                      	Zulu                 Tag = Tag{/* contains filtered or unexported fields */}
                      )

                      func Make

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

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

                        func (*Tag) IsCompact

                        func (t *Tag) IsCompact() bool

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

                          func (Tag) IsRoot

                          func (t Tag) IsRoot() bool

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

                            func (Tag) LanguageTag

                            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

                              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

                                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

                                  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

                                    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

                                      func (t Tag) Tag() language.Tag

                                        Tag returns an internal language Tag version of this tag.