本文整理匯總了Golang中github.com/nicksnyder/go-i18n/i18n/language.Language.Plural方法的典型用法代碼示例。如果您正苦於以下問題:Golang Language.Plural方法的具體用法?Golang Language.Plural怎麽用?Golang Language.Plural使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nicksnyder/go-i18n/i18n/language.Language
的用法示例。
在下文中一共展示了Language.Plural方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: translate
func (b *Bundle) translate(lang *language.Language, translationID string, args ...interface{}) string {
if lang == nil {
return translationID
}
translations := b.translations[lang.Tag]
if translations == nil {
translations = b.fallbackTranslations[lang.Tag]
if translations == nil {
return translationID
}
}
translation := translations[translationID]
if translation == nil {
return translationID
}
var data interface{}
var count interface{}
if argc := len(args); argc > 0 {
if isNumber(args[0]) {
count = args[0]
if argc > 1 {
data = args[1]
}
} else {
data = args[0]
}
}
if count != nil {
if data == nil {
data = map[string]interface{}{"Count": count}
} else {
dataMap := toMap(data)
dataMap["Count"] = count
data = dataMap
}
} else {
dataMap := toMap(data)
if c, ok := dataMap["Count"]; ok {
count = c
}
}
p, _ := lang.Plural(count)
template := translation.Template(p)
if template == nil {
return translationID
}
s := template.Execute(data)
if s == "" {
return translationID
}
return s
}
示例2: translate
func (b *Bundle) translate(lang *language.Language, translationID string, args ...interface{}) string {
if lang == nil {
return translationID
}
translations := b.translations[lang.Tag]
if translations == nil {
translations = b.fallbackTranslations[lang.Tag]
if translations == nil {
return translationID
}
}
translation := translations[translationID]
if translation == nil {
return translationID
}
var count interface{}
if len(args) > 0 && isNumber(args[0]) {
count = args[0]
args = args[1:]
}
plural, _ := lang.Plural(count)
template := translation.Template(plural)
if template == nil {
return translationID
}
var data map[string]interface{}
if len(args) > 0 {
data = toMap(args[0])
}
if isNumber(count) {
if data == nil {
data = map[string]interface{}{"Count": count}
} else {
data["Count"] = count
}
}
s := template.Execute(data)
if s == "" {
return translationID
}
return s
}