本文整理汇总了Golang中golang.org/x/text/language.Tag.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Tag.String方法的具体用法?Golang Tag.String怎么用?Golang Tag.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/text/language.Tag
的用法示例。
在下文中一共展示了Tag.String方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例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
}
示例3: 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
}
示例4: 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
}
示例5: 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...)
}
示例6: 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)
}
}
示例7: 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
}
示例8: identifier
// identifier creates an identifier from the given tag.
func identifier(t language.Tag) string {
return strings.Replace(t.String(), "-", "", -1)
}
示例9: key
func (p *RedisProvider) key(lng *language.Tag, code string) string {
return fmt.Sprintf("locale://%s/%s", lng.String(), code)
}
示例10: GetTranslation
// Gets the translation for the specified key in the language
// represented by tag
func (i18n JsonI18n) GetTranslation(key string, tag language.Tag) string {
if val, ok := i18n.translations[tag.String()]; ok {
return val[key]
}
return key
}
示例11: addTranslationMap
func (i18n JsonI18n) addTranslationMap(languageMap TranslationMap, tag language.Tag) error {
parent := tag.String()
i18n.translations[parent] = languageMap
return nil
}
示例12: Keys
//Keys list locale keys
func (p *DatabaseProvider) Keys(lng *language.Tag) ([]string, error) {
var keys []string
err := p.Db.Model(&Locale{}).Where("lang = ?", lng.String()).Pluck("code", &keys).Error
return keys, err
}
示例13: 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)
}
}