One minute
Pluralization Example in Go
func main() {
text, err := getPluralItemText(1)
if err != nil {
log.Println(err)
}
fmt.Println(text)
text, err = getPluralItemText(10)
if err != nil {
log.Println(err)
}
fmt.Println(text)
}
func getPluralItemText(count int) (string, error) {
msg := plural.Selectf(1, "%d", plural.One, "%[1]d item", plural.Other, "%[1]d items")
key := "%d item"
tag := "en"
lTag := language.MustParse(tag)
err := message.Set(lTag, key, msg)
if err != nil {
return "", err
}
p := message.NewPrinter(language.English)
s := p.Sprintf("%d item", count)
return s, nil
}
Result
1 item
10 items