Documentation ¶
Overview ¶
Package lang parses, validates, and format language tags. Language is formatted according to the RFC 5646 (IETF language tag).
Each language tag is composed of one or more "subtags" separated by hyphens (-). Each subtag is composed of basic Latin letters or digits only. Subtags occur in the following order:
- A single primary language subtag based on a two-letter language code from ISO 639-1
- Up to three optional extended language subtags composed of three letters each, separated by hyphens; (There is currently no extended language subtag registered in the Language Subtag Registry without an equivalent and preferred primary language subtag
- ...
Examples:
- en
- en-GB
- fr-CH
- de-CH
- de-DE
Index ¶
- Variables
- type Matcher
- type Tag
- func (t Tag) Base() string
- func (t Tag) DeepCopy(dst interface{}) error
- func (t *Tag) GobDecode(data []byte) error
- func (t Tag) GobEncode() ([]byte, error)
- func (t Tag) MarshalJSON() ([]byte, error)
- func (t Tag) MarshalText() ([]byte, error)
- func (t Tag) String() string
- func (t *Tag) UnmarshalJSON(data []byte) error
- func (t *Tag) UnmarshalText(p []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( Mul = Tag{T: language.MustParse("mul")} English = Tag{T: language.MustParse("en")} French = Tag{T: language.MustParse("fr")} German = Tag{T: language.MustParse("de")} Italian = Tag{T: language.MustParse("it")} BritishEnglish = Tag{T: language.MustParse("en-GB")} AmericanEnglish = Tag{T: language.MustParse("en-US")} Spanish = Tag{T: language.MustParse("es")} SpainSpanish = Tag{T: language.MustParse("es-ES")} SwissFrench = Tag{T: language.MustParse("fr-CH")} SwissGerman = Tag{T: language.MustParse("de-CH")} )
var ( // ErrUnknownTag indicates that the language tag is well-formed, but unknown ErrUnknownTag = errors.New("unknown language tag") // ErrInvalidTag indicates that the language tag cannot be parsed ErrInvalidTag = errors.New("invalid language tag") )
Functions ¶
This section is empty.
Types ¶
type Tag ¶
Tag is a language tag
func Parse ¶
Parse parses a 2- or 3-letter ISO 639 code. It returns an ErrInvalidLang if s is a well-formed but unknown language identifier or another error if another error occurred.
func ParseAcceptLanguage ¶
ParseAcceptLanguage parses the contents of a Accept-Language header as defined in http://www.ietf.org/rfc/rfc2616.txt
func (Tag) Base ¶
Base returns the base language of the language tag. If the base language is unspecified, an attempt will be made to infer it from the context.
func (Tag) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Tag) MarshalText ¶
func (*Tag) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.