summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/go-i18n/i18n/language/plural.go
blob: 1f3ea5c69b3c7203a06714502454414e8e6708ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package language

import (
	"fmt"
)

// Plural represents a language pluralization form as defined here:
// http://cldr.unicode.org/index/cldr-spec/plural-rules
type Plural string

// All defined plural categories.
const (
	Invalid Plural = "invalid"
	Zero           = "zero"
	One            = "one"
	Two            = "two"
	Few            = "few"
	Many           = "many"
	Other          = "other"
)

// NewPlural returns src as a Plural
// or Invalid and a non-nil error if src is not a valid Plural.
func NewPlural(src string) (Plural, error) {
	switch src {
	case "zero":
		return Zero, nil
	case "one":
		return One, nil
	case "two":
		return Two, nil
	case "few":
		return Few, nil
	case "many":
		return Many, nil
	case "other":
		return Other, nil
	}
	return Invalid, fmt.Errorf("invalid plural category %s", src)
}