• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang language.Tag类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/text/language.Tag的典型用法代码示例。如果您正苦于以下问题:Golang Tag类的具体用法?Golang Tag怎么用?Golang Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Tag类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: formatForLang

func formatForLang(t language.Tag, index []byte) *Format {
	for ; ; t = t.Parent() {
		if x, ok := language.CompactIndex(t); ok {
			return &formats[index[x]]
		}
	}
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:7,代码来源:number.go


示例2: set

func (p *I18n) set(lng *language.Tag, code, message string) {
	lang := lng.String()
	if _, ok := p.Locales[lang]; !ok {
		p.Locales[lang] = make(map[string]string)
	}
	p.Locales[lang][code] = message
}
开发者ID:itpkg,项目名称:chaos,代码行数:7,代码来源:provider.go


示例3: Translate

// Translate one or more strings of text from a source language to a target
// language. All inputs must be in the same language.
//
// The target parameter supplies the language to translate to. The supported
// languages are listed at
// https://cloud.google.com/translate/v2/translate-reference#supported_languages.
// You can also call the SupportedLanguages method.
//
// The returned Translations appear in the same order as the inputs.
func (c *Client) Translate(ctx context.Context, inputs []string, target language.Tag, opts *Options) ([]Translation, error) {
	call := c.raw.Translations.List(inputs, target.String()).Context(ctx)
	if opts != nil {
		if s := opts.Source; s != language.Und {
			call.Source(s.String())
		}
		if f := opts.Format; f != "" {
			call.Format(string(f))
		}
		if m := opts.Model; m != "" {
			call.Model(m)
		}
	}
	res, err := call.Do()
	if err != nil {
		return nil, err
	}
	var ts []Translation
	for _, t := range res.Translations {
		var source language.Tag
		if t.DetectedSourceLanguage != "" {
			source, err = language.Parse(t.DetectedSourceLanguage)
			if err != nil {
				return nil, err
			}
		}
		ts = append(ts, Translation{
			Text:   t.TranslatedText,
			Source: source,
			Model:  t.Model,
		})
	}
	return ts, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:43,代码来源:translate.go


示例4: InfoFromTag

// InfoFromTag returns a Info for the given language tag.
func InfoFromTag(t language.Tag) Info {
	for {
		if index, ok := language.CompactIndex(t); ok {
			return InfoFromLangID(index, t.TypeForKey("nu"))
		}
		t = t.Parent()
	}
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:9,代码来源:number.go


示例5: Get

//Get get locale
func (p *DatabaseProvider) Get(lng *language.Tag, code string) string {
	var l Locale
	if err := p.Db.Where("lang = ? AND code = ?", lng.String(), code).First(&l).Error; err != nil {
		p.Logger.Error(err)
	}
	return l.Message

}
开发者ID:itpkg,项目名称:chaos,代码行数:9,代码来源:database.go


示例6: T

//T translate by lang tag
func (p *I18n) T(lng *language.Tag, code string, args ...interface{}) string {
	lang := lng.String()
	msg := p.Provider.Get(lng, code)
	if len(msg) == 0 {
		if items, ok := p.Locales[lang]; ok {
			msg = items[code]
		}
	}
	return fmt.Sprintf(msg, args...)
}
开发者ID:itpkg,项目名称:chaos,代码行数:11,代码来源:provider.go


示例7: Tailoring

// Tailoring returns a Tailoring for the given locale.  One should
// have completed all calls to Add before calling Tailoring.
func (b *Builder) Tailoring(loc language.Tag) *Tailoring {
	t := &Tailoring{
		id:      loc.String(),
		builder: b,
		index:   b.root.clone(),
	}
	t.index.id = t.id
	b.locale = append(b.locale, t)
	return t
}
开发者ID:hidehide55,项目名称:drive,代码行数:12,代码来源:builder.go


示例8: ldmlBool

func ldmlBool(t language.Tag, old bool, key string) bool {
	switch t.TypeForKey(key) {
	case "true":
		return true
	case "false":
		return false
	default:
		return old
	}
}
开发者ID:ChongFeng,项目名称:beats,代码行数:10,代码来源:option.go


示例9: 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
}
开发者ID:CyCoreSystems,项目名称:coreos-kubernetes,代码行数:13,代码来源:currency.go


示例10: 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
}
开发者ID:joao-parana,项目名称:csfw,代码行数:16,代码来源:language.go


示例11: 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
}
开发者ID:ChongFeng,项目名称:beats,代码行数:17,代码来源:currency.go


示例12: Set

//Set set locale
func (p *DatabaseProvider) Set(lng *language.Tag, code, message string) {
	var l Locale
	var err error
	if p.Db.Where("lang = ? AND code = ?", lng.String(), code).First(&l).RecordNotFound() {
		l.Lang = lng.String()
		l.Code = code
		l.Message = message
		err = p.Db.Create(&l).Error
	} else {
		l.Message = message
		err = p.Db.Save(&l).Error
	}
	if err != nil {
		p.Logger.Error(err)
	}
}
开发者ID:itpkg,项目名称:chaos,代码行数:17,代码来源:database.go


示例13: get

func (c *Catalog) get(tag language.Tag, key string) (msg string, ok bool) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	for ; ; tag = tag.Parent() {
		if msgs, ok := c.index[tag]; ok {
			if statement, ok := msgs[key]; ok {
				// TODO: use type switches when we implement selecting.
				msg := string(statement.(format.String))
				return msg, true
			}
		}
		if tag == language.Und {
			break
		}
	}
	return "", false
}
开发者ID:joao-parana,项目名称:csfw,代码行数:18,代码来源:catalog.go


示例14: SupportedLanguages

// SupportedLanguages returns a list of supported languages for translation.
// The target parameter is the language to use to return localized, human
// readable names of supported languages.
func (c *Client) SupportedLanguages(ctx context.Context, target language.Tag) ([]Language, error) {
	call := c.raw.Languages.List().Context(ctx).Target(target.String())
	res, err := call.Do()
	if err != nil {
		return nil, err
	}
	var ls []Language
	for _, l := range res.Languages {
		tag, err := language.Parse(l.Language)
		if err != nil {
			return nil, err
		}
		ls = append(ls, Language{
			Name: l.Name,
			Tag:  tag,
		})
	}
	return ls, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:22,代码来源:translate.go


示例15: setFromTag

func (o *options) setFromTag(t language.Tag) {
	o.caseLevel = ldmlBool(t, o.caseLevel, "kc")
	o.backwards = ldmlBool(t, o.backwards, "kb")
	o.numeric = ldmlBool(t, o.numeric, "kn")

	// Extract settings from the BCP47 u extension.
	switch t.TypeForKey("ks") { // strength
	case "level1":
		o.ignore[colltab.Secondary] = true
		o.ignore[colltab.Tertiary] = true
	case "level2":
		o.ignore[colltab.Tertiary] = true
	case "level3", "":
		// The default.
	case "level4":
		o.ignore[colltab.Quaternary] = false
	case "identic":
		o.ignore[colltab.Quaternary] = false
		o.ignore[colltab.Identity] = false
	}

	switch t.TypeForKey("ka") {
	case "shifted":
		o.alternate = altShifted
	// The following two types are not official BCP47, but we support them to
	// give access to this otherwise hidden functionality. The name blanked is
	// derived from the LDML name blanked and posix reflects the main use of
	// the shift-trimmed option.
	case "blanked":
		o.alternate = altBlanked
	case "posix":
		o.alternate = altShiftTrimmed
	}

	// TODO: caseFirst ("kf"), reorder ("kr"), and maybe variableTop ("vt").

	// Not used:
	// - normalization ("kk", not necessary for this implementation)
	// - hiraganaQuatenary ("kh", obsolete)
}
开发者ID:ChongFeng,项目名称:beats,代码行数:40,代码来源:option.go


示例16: identifier

// identifier creates an identifier from the given tag.
func identifier(t language.Tag) string {
	return strings.Replace(t.String(), "-", "", -1)
}
开发者ID:npchp110,项目名称:text,代码行数:4,代码来源:maketables.go


示例17: key

func (p *RedisProvider) key(lng *language.Tag, code string) string {
	return fmt.Sprintf("locale://%s/%s", lng.String(), code)
}
开发者ID:itpkg,项目名称:chaos,代码行数:3,代码来源:redis.go


示例18: Del

//Del del locale
func (p *DatabaseProvider) Del(lng *language.Tag, code string) {
	if err := p.Db.Where("lang = ? AND code = ?", lng.String(), code).Delete(Locale{}).Error; err != nil {
		p.Logger.Error(err)
	}
}
开发者ID:itpkg,项目名称:chaos,代码行数:6,代码来源:database.go


示例19: parent

// parent computes the structural parent. This means inheritance may change
// script. So, unlike the CLDR parent, parent(zh-Hant) == zh.
func parent(t language.Tag) language.Tag {
	if t.TypeForKey("va") != "" {
		t, _ = t.SetTypeForKey("va", "")
		return t
	}
	result := language.Und
	if b, s, r := t.Raw(); (r != language.Region{}) {
		result, _ = language.Raw.Compose(b, s, t.Extensions())
	} else if (s != language.Script{}) {
		result, _ = language.Raw.Compose(b, t.Extensions())
	} else if (b != language.Base{}) {
		result, _ = language.Raw.Compose(t.Extensions())
	}
	return result
}
开发者ID:Zhoutall,项目名称:beats,代码行数:17,代码来源:colltab.go


示例20: MatchLang

// MatchLang finds the index of t in tags, using a matching algorithm used for
// collation and search. tags[0] must be language.Und, the remaining tags should
// be sorted alphabetically.
//
// Language matching for collation and search is different from the matching
// defined by language.Matcher: the (inferred) base language must be an exact
// match for the relevant fields. For example, "gsw" should not match "de".
// Also the parent relation is different, as a parent may have a different
// script. So usually the parent of zh-Hant is und, whereas for MatchLang it is
// zh.
func MatchLang(t language.Tag, tags []language.Tag) int {
	// Canonicalize the values, including collapsing macro languages.
	t, _ = language.All.Canonicalize(t)

	base, conf := t.Base()
	// Estimate the base language, but only use high-confidence values.
	if conf < language.High {
		// The root locale supports "search" and "standard". We assume that any
		// implementation will only use one of both.
		return 0
	}

	// Maximize base and script and normalize the tag.
	if _, s, r := t.Raw(); (r != language.Region{}) {
		p, _ := language.Raw.Compose(base, s, r)
		// Taking the parent forces the script to be maximized.
		p = p.Parent()
		// Add back region and extensions.
		t, _ = language.Raw.Compose(p, r, t.Extensions())
	} else {
		// Set the maximized base language.
		t, _ = language.Raw.Compose(base, s, t.Extensions())
	}

	// Find start index of the language tag.
	start := 1 + sort.Search(len(tags)-1, func(i int) bool {
		b, _, _ := tags[i+1].Raw()
		return base.String() <= b.String()
	})
	if start < len(tags) {
		if b, _, _ := tags[start].Raw(); b != base {
			return 0
		}
	}

	// Besides the base language, script and region, only the collation type and
	// the custom variant defined in the 'u' extension are used to distinguish a
	// locale.
	// Strip all variants and extensions and add back the custom variant.
	tdef, _ := language.Raw.Compose(t.Raw())
	tdef, _ = tdef.SetTypeForKey("va", t.TypeForKey("va"))

	// First search for a specialized collation type, if present.
	try := []language.Tag{tdef}
	if co := t.TypeForKey("co"); co != "" {
		tco, _ := tdef.SetTypeForKey("co", co)
		try = []language.Tag{tco, tdef}
	}

	for _, tx := range try {
		for ; tx != language.Und; tx = parent(tx) {
			for i, t := range tags[start:] {
				if b, _, _ := t.Raw(); b != base {
					break
				}
				if tx == t {
					return start + i
				}
			}
		}
	}
	return 0
}
开发者ID:Zhoutall,项目名称:beats,代码行数:73,代码来源:colltab.go



注:本文中的golang.org/x/text/language.Tag类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang transform.Bytes函数代码示例发布时间:2022-05-28
下一篇:
Golang language.Region类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap