type MatchOption … // PreferSameScript will, in the absence of a match, result in the first // preferred tag with the same script as a supported tag to match this supported // tag. The default is currently true, but this may change in the future. func PreferSameScript(preferSame bool) MatchOption { … } // MatchStrings parses and matches the given strings until one of them matches // the language in the Matcher. A string may be an Accept-Language header as // handled by ParseAcceptLanguage. The default language is returned if no // other language matched. func MatchStrings(m Matcher, lang ...string) (tag Tag, index int) { … } type Matcher … // Comprehends reports the confidence score for a speaker of a given language // to being able to comprehend the written form of an alternative language. func Comprehends(speaker, alternative Tag) Confidence { … } // NewMatcher returns a Matcher that matches an ordered list of preferred tags // against a list of supported tags based on written intelligibility, closeness // of dialect, equivalence of subtags and various other rules. It is initialized // with the list of supported tags. The first element is used as the default // value in case no match is found. // // Its Match method matches the first of the given Tags to reach a certain // confidence threshold. The tags passed to Match should therefore be specified // in order of preference. Extensions are ignored for matching. // // The index returned by the Match method corresponds to the index of the // matched tag in t, but is augmented with the Unicode extension ('u')of the // corresponding preferred tag. This allows user locale options to be passed // transparently. func NewMatcher(t []Tag, options ...MatchOption) Matcher { … } func (m *matcher) Match(want ...Tag) (t Tag, index int, c Confidence) { … } var ErrMissingLikelyTagsData … type matcher … type matchHeader … type haveTag … func makeHaveTag(tag language.Tag, index int) (haveTag, language.Language) { … } // altScript returns an alternative script that may match the given script with // a low confidence. At the moment, the langMatch data allows for at most one // script to map to another and we rely on this to keep the code simple. func altScript(l language.Language, s language.Script) language.Script { … } // addIfNew adds a haveTag to the list of tags only if it is a unique tag. // Tags that have the same maximized values are linked by index. func (h *matchHeader) addIfNew(n haveTag, exact bool) { … } // header returns the matchHeader for the given language. It creates one if // it doesn't already exist. func (m *matcher) header(l language.Language) *matchHeader { … } func toConf(d uint8) Confidence { … } // newMatcher builds an index for the given supported tags and returns it as // a matcher. It also expands the index by considering various equivalence classes // for a given tag. func newMatcher(supported []Tag, options []MatchOption) *matcher { … } // getBest gets the best matching tag in m for any of the given tags, taking into // account the order of preference of the given tags. func (m *matcher) getBest(want ...Tag) (got *haveTag, orig language.Tag, c Confidence) { … } type bestMatch … // update updates the existing best match if the new pair is considered to be a // better match. To determine if the given pair is a better match, it first // computes the rough confidence level. If this surpasses the current match, it // will replace it and update the tie-breaker rule cache. If there is a tie, it // proceeds with applying a series of tie-breaker rules. If there is no // conclusive winner after applying the tie-breaker rules, it leaves the current // match as the preferred match. // // If pin is true and have and tag are a strong match, it will henceforth only // consider matches for this language. This corresponds to the idea that most // users have a strong preference for the first defined language. A user can // still prefer a second language over a dialect of the preferred language by // explicitly specifying dialects, e.g. "en, nl, en-GB". In this case pin should // be false. func (m *bestMatch) update(have *haveTag, tag language.Tag, maxScript language.Script, maxRegion language.Region, pin bool) { … } func isParadigmLocale(lang language.Language, r language.Region) bool { … } // regionGroupDist computes the distance between two regions based on their // CLDR grouping. func regionGroupDist(a, b language.Region, script language.Script, lang language.Language) (dist uint8, same bool) { … } // equalsRest compares everything except the language. func equalsRest(a, b language.Tag) bool { … } // isExactEquivalent returns true if canonicalizing the language will not alter // the script or region of a tag. func isExactEquivalent(l language.Language) bool { … } var notEquivalent … func init() { … }