package language
import "github.com/nicksnyder/go-i18n/i18n/language"
Package language defines languages that implement CLDR pluralization.
Index ¶
- Constants
- func Add(l *Language)
- func NormalizeTag(tag string) string
- type Language
- func MustParse(src string) []*Language
- func Parse(src string) []*Language
- func (l *Language) MatchingTags() []string
- func (l *Language) String() string
- type Plural
- type PluralSpec
Constants ¶
const ( Invalid Plural = "invalid" Zero = "zero" One = "one" Two = "two" Few = "few" Many = "many" Other = "other" )
All defined plural categories.
Functions ¶
func Add ¶
func Add(l *Language)
Add adds support for a new language.
func NormalizeTag ¶
NormalizeTag returns a language tag with all lower-case characters and dashes "-" instead of underscores "_"
Types ¶
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 *PluralSpec }
Language is a written human language.
func MustParse ¶
MustParse is similar to Parse except it panics instead of retuning a nil Language.
func Parse ¶
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 ¶
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 ¶
type Plural ¶
type Plural string
Plural represents a language pluralization form as defined here: http://cldr.unicode.org/index/cldr-spec/plural-rules
func NewPlural ¶
NewPlural returns src as a Plural or Invalid and a non-nil error if src is not a valid Plural.
type PluralSpec ¶
PluralSpec 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
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.
Source Files ¶
language.go operands.go plural.go pluralspec.go pluralspec_gen.go
Directories ¶
Path | Synopsis |
---|---|
i18n/language/codegen |
- Version
- v1.8.1
- Published
- May 12, 2017
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- 1 day ago –
Tools for package owners.