plural

package
v0.0.0-...-9e2f80a Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2017 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package plural provides utilities for handling linguistic plurals in text.

The definitions in this package are based on the plural rule handling defined in CLDR. See http://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules for details.

Index

Constants

View Source
const CLDRVersion = "30"

CLDRVersion is the CLDR version from which the tables in this package are derived.

Variables

This section is empty.

Functions

This section is empty.

Types

type Form

type Form byte

Form defines a plural form.

Not all languages support all forms. Also, the meaning of each form varies per language. It is important to note that the name of a form does not necessarily correspond one-to-one with the set of numbers. For instance, for Croation, One matches not only 1, but also 11, 21, etc.

Each language must at least support the form "other".

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

type Rules

type Rules struct {
	// contains filtered or unexported fields
}

Rules defines the plural rules for all languages for a certain plural type.

This package is UNDER CONSTRUCTION and its API may change.

var (
	// Cardinal defines the plural rules for numbers indicating quantities.
	Cardinal *Rules = cardinal

	// Ordinal defines the plural rules for numbers indicating position
	// (first, second, etc.).
	Ordinal *Rules = ordinal
)

func (*Rules) MatchDigits

func (p *Rules) MatchDigits(t language.Tag, digits []byte, exp, scale int) Form

MatchDigits computes the plural form for the given language and the given decimal floating point digits. The digits are stored in big-endian order and are of value byte(0) - byte(9). The floating point position is indicated by exp and the number of visible decimals is scale. All leading and trailing zeros may be omitted from digits.

The following table contains examples of possible arguments to represent the given numbers.

decimal    digits              exp    scale
123        []byte{1, 2, 3}     3      0
123.4      []byte{1, 2, 3, 4}  3      1
123.40     []byte{1, 2, 3, 4}  3      2
100000     []byte{1}           6......0
100000.00  []byte{1}           6......3

Jump to

Keyboard shortcuts

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