plurals

package
v2.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package plurals is an easy-to-use wrapper around the /x/text/feature/plural package.

Plural rules controls how, for a given locale, plurals are counted in forms such as "1st", "2nd", "3rd", or "1 cat", "2 cats", etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Form

type Form byte
const (
	Other Form = iota
	Zero
	One
	Two
	Few
	Many
)

type Rules

type Rules interface {
	// Ordinal is used to determine e.g. 0 days, 1 day, 2 days. For example,
	// for locale "en", Ordinal("2") == Many.
	Ordinal(number string) Form

	// Cardinal is used to determine e.g. 1st, 2nd, 3rd. For example,
	// for locale "en", Cardinal("3") == Few.
	Cardinal(number string) Form
}

Rules implements plural forms of a number for a given locale.

Numbers represented by a string must be formatted with the ASCII digits '0' to '9', and optionally with a single decimal point encoded as the ASCII character '.'.

If an argument is of the wrong format, or out of range of an int64, the result will be Other.

func New

func New(locale language.Tag) Rules

New returns a value implementing the Rules interface for that locale.

e.g. plurals.New(language.MustParse("en"))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL