# plural

package
v2.4.0 Latest Latest

Go to latest
Published: Jan 31, 2024 License: MIT

## Documentation ¶

### Overview ¶

Package plural provides support for pluralizing messages according to CLDR rules http://cldr.unicode.org/index/cldr-spec/plural-rules

### Constants ¶

This section is empty.

### Variables ¶

This section is empty.

### Functions ¶

This section is empty.

### Types ¶

#### type Form ¶

`type Form string`

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

```const (
Invalid Form = ""
Zero    Form = "zero"
One     Form = "one"
Two     Form = "two"
Few     Form = "few"
Many    Form = "many"
Other   Form = "other"
)```

All defined plural forms.

#### type Operands ¶

```type Operands struct {
N float64 // absolute value of the source number (integer and decimals)
I int64   // integer digits of n
V int64   // number of visible fraction digits in n, with trailing zeros
W int64   // number of visible fraction digits in n, without trailing zeros
F int64   // visible fractional digits in n, with trailing zeros
T int64   // visible fractional digits in n, without trailing zeros
C int64   // compact decimal exponent value: exponent of the power of 10 used in compact decimal formatting.
}```

Operands is a representation of http://unicode.org/reports/tr35/tr35-numbers.html#Operands If there is a compact decimal exponent value C, then the N, I, V, W, F, and T values are computed after shifting the decimal point in the original by the ‘c’ value. So for 1.2c3, the values are the same as those of 1200: i=1200 and f=0. Similarly, 1.2005c3 has i=1200 and f=5 (corresponding to 1200.5).

#### func NewOperands ¶

`func NewOperands(number interface{}) (*Operands, error)`

NewOperands returns the operands for number.

#### func (*Operands) NEqualsAny ¶

`func (o *Operands) NEqualsAny(any ...int64) bool`

NEqualsAny returns true if o represents an integer equal to any of the arguments.

#### func (*Operands) NInRange ¶

`func (o *Operands) NInRange(from, to int64) bool`

NInRange returns true if o represents an integer in the closed interval [from, to].

#### func (*Operands) NModEqualsAny ¶

`func (o *Operands) NModEqualsAny(mod int64, any ...int64) bool`

NModEqualsAny returns true if o represents an integer equal to any of the arguments modulo mod.

#### func (*Operands) NModInRange ¶

`func (o *Operands) NModInRange(mod, from, to int64) bool`

NModInRange returns true if o represents an integer in the closed interval [from, to] modulo mod.

#### type Rule ¶

```type Rule struct {
PluralForms    map[Form]struct{}
PluralFormFunc func(*Operands) Form
}```

Rule defines the CLDR plural rules for a language. http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html http://unicode.org/reports/tr35/tr35-numbers.html#Operands

#### type Rules ¶

`type Rules map[language.Tag]*Rule`

Rules is a set of plural rules by language tag.

#### func DefaultRules ¶

`func DefaultRules() Rules`

DefaultRules returns a map of Rules generated from CLDR language data.

#### func (Rules) Rule ¶

`func (r Rules) Rule(tag language.Tag) *Rule`

Rule returns the closest matching plural rule for the language tag or nil if no rule could be found.

Path Synopsis