// index returns the index of the tag for the given base, script and region or // its parent if the tag is not available. If the match is for a parent entry, // the excess script and region are returned. func (ts *tagSet) index(base language.Base, scr language.Script, reg language.Region) (int, language.Script, language.Region) { lang := base.String() index := -1 if (scr != language.Script{} || reg != language.Region{}) { if scr == zzzz { scr = language.Script{} } if reg == zz { reg = language.Region{} } i := sort.SearchStrings(ts.long, lang) // All entries have either a script or a region and not both. scrStr, regStr := scr.String(), reg.String() for ; i < len(ts.long) && strings.HasPrefix(ts.long[i], lang); i++ { if s := ts.long[i][len(lang)+1:]; s == scrStr { scr = language.Script{} index = i + ts.single.len() break } else if s == regStr { reg = language.Region{} index = i + ts.single.len() break } } } if index == -1 { index = ts.single.index(lang) } return index, scr, reg }
// GetLocale generates a locale from a base and a region and may use an optional script. // lang // lang_script // lang_script_region // lang_region (aliases to lang_script_region) func GetLocale(b language.Base, r language.Region, s ...language.Script) string { ret := b.String() if len(s) == 1 { ret += LocaleSeparator + s[0].String() } return ret + LocaleSeparator + r.String() }