Version: v1.10.1 Latest Latest

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

Go to latest
Published: May 19, 2019 License: MIT Imports: 3 Imported by: 237



Package language defines languages that implement CLDR pluralization.



View Source
const (
	Invalid Plural = "invalid"
	Zero           = "zero"
	One            = "one"
	Two            = "two"
	Few            = "few"
	Many           = "many"
	Other          = "other"

All defined plural categories.


This section is empty.


func Add

func Add(l *Language)

Add adds support for a new language.

func NormalizeTag

func NormalizeTag(tag string) string

NormalizeTag returns a language tag with all lower-case characters and dashes "-" instead of underscores "_"

func RegisterPluralSpec added in v1.9.0

func RegisterPluralSpec(ids []string, ps *PluralSpec)

RegisterPluralSpec registers a new plural spec for the language ids.


type Language

type Language struct {
	// Tag uniquely identifies the language as defined by RFC 5646.
	// Most language tags are a two character language code (ISO 639-1)
	// optionally followed by a dash and a two character country code (ISO 3166-1).
	// (e.g. en, pt-br)
	Tag string

Language is a written human language.

func MustParse

func MustParse(src string) []*Language

MustParse is similar to Parse except it panics instead of retuning a nil Language.

func Parse

func Parse(src string) []*Language

Parse returns a slice of supported languages found in src or nil if none are found. It can parse language tags and Accept-Language headers.

func (*Language) MatchingTags added in v1.1.0

func (l *Language) MatchingTags() []string

MatchingTags returns the set of language tags that map to this Language. e.g. "zh-hans-cn" yields {"zh", "zh-hans", "zh-hans-cn"} BUG: This should be computed once and stored as a field on Language for efficiency,

but this would require changing how Languages are constructed.

func (*Language) String

func (l *Language) String() string

type Operands added in v1.9.0

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

Operands is a representation of

func (*Operands) NequalsAny added in v1.9.0

func (o *Operands) NequalsAny(any ...int64) bool

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

func (*Operands) NinRange added in v1.9.0

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 added in v1.9.0

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 added in v1.9.0

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 Plural

type Plural string

Plural represents a language pluralization form as defined here:

func NewPlural

func NewPlural(src string) (Plural, error)

NewPlural returns src as a Plural or Invalid and a non-nil error if src is not a valid Plural.

type PluralSpec

type PluralSpec struct {
	Plurals    map[Plural]struct{}
	PluralFunc func(*Operands) Plural

PluralSpec defines the CLDR plural rules for a language.

func GetPluralSpec added in v1.10.0

func GetPluralSpec(tag string) *PluralSpec

GetPluralSpec returns the PluralSpec that matches the longest prefix of tag. It returns nil if no PluralSpec matches tag.

func (*PluralSpec) Plural

func (ps *PluralSpec) Plural(number interface{}) (Plural, error)

Plural returns the plural category for number as defined by the language's CLDR plural rules.


Path Synopsis

Jump to

Keyboard shortcuts

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