Documentation ¶
Overview ¶
Package messageformat implements ICU messages formatting for Go. see http://userguide.icu-project.org/formatparse/messages inspired by https://github.com/SlexAxton/messageformat.js
Index ¶
- Constants
- Variables
- func AddChild(parent, child Node)
- type Choice
- type Complexity
- type Container
- func (nd *Container) Children() []Node
- func (nd *Container) Complexity() Complexity
- func (nd *Container) Culture() language.Tag
- func (nd *Container) Data() interface{}
- func (nd *Container) Format(mf *MessageFormat, output *bytes.Buffer, data Data, pound string) error
- func (nd *Container) Parent() Node
- func (nd *Container) Root() Node
- func (nd *Container) ToString(output *bytes.Buffer) (err error)
- func (nd *Container) Type() string
- type Data
- type Equal
- type Equals
- type Literal
- type MessageFormat
- type Node
- type NothingSkipper
- type Ordinal
- type Parser
- type Plural
- type PluralSkipper
- type Root
- type Select
- func (nd *Select) Choices() []Choice
- func (nd *Select) ChoicesUnsorted() []Choice
- func (nd *Select) Format(mf *MessageFormat, output *bytes.Buffer, data Data, _ string) error
- func (s *Select) Len() int
- func (s *Select) Less(i, j int) bool
- func (nd *Select) Other() Node
- func (s *Select) Swap(i, j int)
- func (nd *Select) ToString(output *bytes.Buffer) error
- func (nd *Select) Type() string
- func (nd *Select) Varname() string
- type SelectNode
- type SelectSkipper
- type Var
Constants ¶
const ( EscapeChar = '\\' OpenChar = '{' CloseChar = '}' PartChar = ',' PoundChar = '#' EqualChar = '=' )
Variables ¶
var Funcs = template.FuncMap{ "mfPluralNode": ParsePlural, "mfPluralNodeWithData": ParsePluralWithData, }
Functions ¶
Types ¶
type Complexity ¶
type Complexity int
const ( NoComplexity Complexity = iota SingleLiteral SingleRoad Complex )
func (Complexity) IsComplex ¶
func (c Complexity) IsComplex() bool
func (Complexity) IsSingleLiteral ¶
func (c Complexity) IsSingleLiteral() bool
func (Complexity) IsSingleRoad ¶
func (c Complexity) IsSingleRoad() bool
func (Complexity) String ¶
func (i Complexity) String() string
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func (*Container) Complexity ¶
func (nd *Container) Complexity() Complexity
type MessageFormat ¶
type MessageFormat struct {
// contains filtered or unexported fields
}
func (*MessageFormat) Format ¶
func (x *MessageFormat) Format() (string, error)
func (*MessageFormat) FormatData ¶
func (x *MessageFormat) FormatData(data Data) (string, error)
func (*MessageFormat) HasSelect ¶
func (x *MessageFormat) HasSelect() bool
func (*MessageFormat) Root ¶
func (x *MessageFormat) Root() Node
func (*MessageFormat) ToString ¶
func (x *MessageFormat) ToString() (string, error)
type Node ¶
type Node interface { Type() string ToString(output *bytes.Buffer) error Culture() language.Tag Complexity() Complexity Data() interface{} Root() Node Parent() Node Children() []Node Format(mf *MessageFormat, buf *bytes.Buffer, data Data, pound string) error // contains filtered or unexported methods }
type NothingSkipper ¶
type NothingSkipper struct{}
type Ordinal ¶
type Ordinal struct {
Select
}
func (*Ordinal) Format ¶
It will returns an error if : - the associated value can't be convert to string or to an int (i.e. bool, ...) - the pluralFunc is not defined (MessageFormat.getNamedKey)
It will falls back to the "other" choice if : - its key can't be found in the given map - the computed named key (MessageFormat.getNamedKey) is not a key of the given map
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) Parse ¶
func (x *Parser) Parse(input string, data interface{}) (*MessageFormat, error)
func (*Parser) SkipForPlural ¶
SkipForPlural must be called before Parse.
type Plural ¶
func (*Plural) Format ¶
It will returns an error if : - the associated value can't be convert to string or to an int (i.e. bool, ...) - the pluralFunc is not defined (MessageFormat.getNamedKey)
It will falls back to the "other" choice if : - its key can't be found in the given map - the computed named key (MessageFormat.getNamedKey) is not a key of the given map
type PluralSkipper ¶
type PluralSkipper struct {
// contains filtered or unexported fields
}
func NewPluralSkipper ¶
func NewPluralSkipper(culture language.Tag, ordinal bool) (*PluralSkipper, error)
type Root ¶
type Root struct { Container // contains filtered or unexported fields }
func (*Root) Complexity ¶
func (nd *Root) Complexity() Complexity
type Select ¶
type Select struct { Container ChoicesMap map[string]Node // contains filtered or unexported fields }