// FromTag reports the most likely currency for the given tag. It considers the
// currency defined in the -u extension and infers the region if necessary.
func FromTag(t language.Tag) (Unit, language.Confidence) {
	if cur := t.TypeForKey("cu"); len(cur) == 3 {
		c, _ := ParseISO(cur)
		return c, language.Exact
	}
	r, conf := t.Region()
	if cur, ok := FromRegion(r); ok {
		return cur, conf
	}
	return Unit{}, language.No
}
Example #2
0
// GetLanguages returns a list of languages as a key/value slice. Odd index/key = locale,
// even index/value = Humanized readable string. The humanized strings contains the language
// name in its language and language name in requested tag
func GetLanguages(t language.Tag) []string {
	var ret = make([]string, len(tags)*2)
	n := getDict(t)
	i := 0
	for _, t := range tags {
		b, _ := t.Base()
		r, _ := t.Region()
		ret[i] = GetLocale(b, r)
		ret[i+1] = fmt.Sprintf("%-20s (%s)", display.Self.Name(t), n.Languages().Name(t))
		i = i + 2
	}
	return ret
}
Example #3
0
// FromTag reports the most likely currency for the given tag. It considers the
// currency defined in the -u extension and infers the region if necessary.
func FromTag(t language.Tag) (Currency, language.Confidence) {
	if cur := t.TypeForKey("cu"); len(cur) == 3 {
		var buf [3]byte
		copy(buf[:], cur)
		tag.FixCase("XXX", buf[:])
		if x := currency.Index(buf[:]); x > 0 {
			return Currency{uint16(x)}, language.Exact
		}
	}
	r, conf := t.Region()
	if cur, ok := FromRegion(r); ok {
		return cur, conf
	}
	return Currency{}, language.No
}