package language
Import Path
golang.org/x/text/internal/language (on go.dev)
Dependency Relation
imports 7 packages, and imported by 2 packages
Involved Source Files
common.go
compact.go
compose.go
coverage.go
language.go
lookup.go
match.go
parse.go
tables.go
tags.go
Package-Level Type Names (total 10)
AliasType is the type of an alias in AliasMap.
func Language.Canonicalize() (Language, AliasType)
const AliasTypeUnknown
const Deprecated
const Legacy
const Macro
A Builder allows constructing a Tag from individual components.
Its main user is Compose in the top-level language package.
Tag Tag
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.
AddVariant adds any number of variants.
ClearExtensions removes any extensions previously added, including those
copied from a Tag in SetTag.
ClearVariants removes any variants previously added, including those
copied from a Tag in SetTag.
Make returns a new Tag from the current settings.
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.
SetTag copies all the settings from a given Tag. Any previously set values
are discarded.
CompactCoreInfo is a compact integer with the three core tags encoded.
Tag generates a tag from c.
func GetCompactCore(t Tag) (cci CompactCoreInfo, ok bool)
( Language) Canonicalize() (Language, AliasType)
ISO3 returns the ISO 639-3 language code.
IsPrivateUse reports whether this language code is reserved for private use.
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.
StringToBuf writes the string to b and returns the number of bytes
written. cap(b) must be >= 3.
SuppressScript returns the script marked as SuppressScript in the IANA
language tag repository, or 0 if there is no such script.
Language : fmt.Stringer
Language : github.com/ChrisTrenkamp/goxpath/tree.Result
func BaseLanguages() []Language
func MustParseBase(s string) Language
func ParseBase(s string) (l Language, err error)
func Language.Canonicalize() (Language, AliasType)
func Tag.Raw() (b Language, s Script, r 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.
Contains returns whether Region c is contained by Region r. It returns true
if c == r.
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".
IsCountry returns whether this region is a country or autonomous area. This
includes non-standard definitions from CLDR.
IsGroup returns whether this region defines a collection of regions. This
includes non-standard definitions from CLDR.
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.
M49 returns the UN M.49 encoding of r, or 0 if this encoding
is not defined for r.
String returns the BCP 47 representation for the region.
It returns "ZZ" for an unspecified region.
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.
Region : fmt.Stringer
Region : github.com/ChrisTrenkamp/goxpath/tree.Result
func EncodeM49(r int) (Region, error)
func MustParseRegion(s string) Region
func ParseRegion(s string) (r Region, err error)
func Region.Canonicalize() Region
func Region.TLD() (Region, error)
func Tag.Raw() (b Language, s Script, r Region)
func Region.Contains(c Region) bool
IsPrivateUse reports whether this script code is reserved for private use.
String returns the script code in title case.
It returns "Zzzz" for an unspecified script.
Script : fmt.Stringer
Script : github.com/ChrisTrenkamp/goxpath/tree.Result
func MustParseScript(s string) Script
func ParseScript(s string) (scr Script, err error)
func Language.SuppressScript() Script
func Tag.Raw() (b Language, s Script, r Region)
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.
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.
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.
Extensions returns all extensions of t.
HasExtensions reports whether t has extensions.
HasString reports whether this tag defines more than just the raw
components.
HasVariants reports whether t has variants.
IsPrivateUse reports whether the Tag consists solely of an IsPrivateUse use
tag.
IsRoot returns true if t is equal to language "und".
MarshalText implements encoding.TextMarshaler.
Maximize returns a new tag with missing tags filled in.
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.
Raw returns the raw base language, script and region, without making an
attempt to infer their values.
TODO: consider removing
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.
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.
String returns the canonical string representation of the language tag.
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.
UnmarshalText implements encoding.TextUnmarshaler.
VariantOrPrivateUseTags returns variants or private use tags.
Variants returns the part of the tag holding all variants or the empty string
if there are no variants defined.
Tag : encoding.TextMarshaler
*Tag : encoding.TextUnmarshaler
Tag : fmt.Stringer
Tag : github.com/ChrisTrenkamp/goxpath/tree.Result
func Make(s string) Tag
func MustParse(s string) Tag
func Parse(s string) (t Tag, err error)
func (*Builder).Make() Tag
func CompactCoreInfo.Tag() Tag
func Tag.Maximize() (Tag, error)
func Tag.Parent() Tag
func Tag.SetTypeForKey(key, value string) (Tag, error)
func golang.org/x/text/internal/language/compact.ID.Tag() Tag
func golang.org/x/text/internal/language/compact.Tag.Tag() Tag
func GetCompactCore(t Tag) (cci CompactCoreInfo, ok bool)
func (*Builder).SetTag(t Tag)
func golang.org/x/text/internal/language/compact.FromTag(t Tag) (id compact.ID, exact bool)
func golang.org/x/text/internal/language/compact.Make(t Tag) (tag compact.Tag)
var Und
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.
Error implements the error interface.
Subtag returns the subtag for which the error occurred.
ValueError : golang.org/x/text/language.ValueError
ValueError : error
func NewValueError(tag []byte) ValueError
Package-Level Functions (total 15)
BaseLanguages returns the list of all supported base languages. It generates
the list by traversing the internal structures.
EncodeM49 returns the Region for the given UN M.49 code.
It returns an error if r is not a valid code.
GetCompactCore generates a uint32 value that is guaranteed to be unique for
different language, region, and script values.
Make is a convenience wrapper for Parse that omits the error.
In case of an error, a sensible default is returned.
MustParse is like Parse, but panics if the given BCP 47 tag cannot be parsed.
It simplifies safe initialization of Tag values.
MustParseBase is like ParseBase, but panics if the given base cannot be parsed.
It simplifies safe initialization of Base values.
MustParseRegion is like ParseRegion, but panics if the given region cannot be
parsed. It simplifies safe initialization of Region values.
MustParseScript is like ParseScript, but panics if the given script cannot be
parsed. It simplifies safe initialization of Script values.
NewValueError creates a new ValueError.
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.
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.
ParseExtension parses s as an extension and returns it on success.
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.
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.
ParseVariant parses and returns a Variant. An error is returned if s is not
a valid variant.
Package-Level Variables (total 6)
AliasMap maps langIDs to their suggested replacements.
Size: 772 bytes, 193 elements
Size: 193 bytes, 193 elements
ErrDuplicateKey is returned when a tag contains the same key twice with
different values in the -u section.
ErrMissingLikelyTagsData indicates no information was available
to compute likely values of missing tags.
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?
Und is the root language.
Package-Level Constants (total 8)
const AliasTypeUnknown AliasType = -1
CLDRVersion is the CLDR version from which the tables in this package are derived.
const Deprecated AliasType = 0 const NumLanguages = 8798 const NumRegions = 358 const NumScripts = 261
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |