本文整理汇总了Golang中golang.org/x/text/language.Tag.Region方法的典型用法代码示例。如果您正苦于以下问题:Golang Tag.Region方法的具体用法?Golang Tag.Region怎么用?Golang Tag.Region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/text/language.Tag
的用法示例。
在下文中一共展示了Tag.Region方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FromTag
// 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
}
示例2: GetLanguages
// 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
}
示例3: FromTag
// 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
}