message

package
v0.0.0-...-07e11ac Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCase = "other"

{ GENDER, select,

    male {He}
    female {She}
    other {They}
} liked this.

Variables

View Source
var ErrNoDefaultCase = errors.New("no default case")

Functions

This section is empty.

Types

type Content

type Content string

func (Content) Eval

func (c Content) Eval(_ Context) (string, error)

type Context

type Context map[string]any

func (Context) Any

func (c Context) Any(name string) (any, error)

func (Context) Float64

func (c Context) Float64(key string) (float64, error)

func (Context) Int64

func (c Context) Int64(key string) (int64, error)

func (Context) Set

func (c Context) Set(name string, value any)

func (Context) String

func (c Context) String(name string) (string, error)

func (Context) Time

func (c Context) Time(key string) (time.Time, error)

type Datetime

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

func NewDate

func NewDate(argName string, format DatetimeFormat, lang language.Tag) *Datetime

func NewDatetime

func NewDatetime(argName string, format DatetimeFormat, lang language.Tag) *Datetime

func NewTime

func NewTime(argName string, format DatetimeFormat, lang language.Tag) *Datetime

func (Datetime) Eval

func (dt Datetime) Eval(ctx Context) (string, error)

type DatetimeFormat

type DatetimeFormat int
const (
	NoneDatetimeFormat   DatetimeFormat = iota
	ShortDatetimeFormat                 // 1/2/06, 3:04 PM
	MediumDatetimeFormat                // Jan 2, 2006, 3:04:05 PM
	LongDatetimeFormat                  // January 2, 2006 at 3:04:05 PM UTC

	// TODO: go std time formater does not have full forms of local abbreviation
	FullDatetimeFormat // Monday, January 2, 2006 at 3:04:05 PM Coordinated Universal Time
)

type Evalable

type Evalable interface {
	Eval(ctx Context) (string, error)
}

func Build

func Build(in parse.Message, lang language.Tag) (Evalable, error)

type FunctionArg

type FunctionArg struct {
	Name    string
	ArgName string
	Param   string
}

{age, number, integer}

type Message

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

func (*Message) Eval

func (m *Message) Eval(ctx Context) (string, error)

type Number

type Number struct {
	ArgName string
	Format  NumberFormat
	Lang    language.Tag
	// contains filtered or unexported fields
}

func NewNumber

func NewNumber(argName string, format NumberFormat, lang language.Tag) *Number

func (Number) Eval

func (n Number) Eval(ctx Context) (string, error)

type NumberFormat

type NumberFormat int
const (
	NoneNumberFormat NumberFormat = iota
	IntegerNumberFormat
	PercentNumberFormat
)

type PlainArg

type PlainArg string

func (PlainArg) Eval

func (pa PlainArg) Eval(ctx Context) (string, error)

type Plural

type Plural struct {
	ArgName string
	Lang    language.Tag
	Offset  int
	EqCases map[uint64]Evalable
	Cases   map[plural.Form]Evalable
	// contains filtered or unexported fields
}

{ COUNT, plural,

    =0 {There are no results.}
    one {There is one result.}
    other {There are # results.}
}

func NewPlural

func NewPlural(argName string, lang language.Tag, offset int) *Plural

func NewSelectOrdinal

func NewSelectOrdinal(argName string, lang language.Tag, offset int) *Plural

func (*Plural) Eval

func (p *Plural) Eval(ctx Context) (string, error)

type PluralCase

type PluralCase struct {
	Key  string
	Eval Evalable
}

type Select

type Select struct {
	ArgName string
	Cases   map[string]Evalable
}

func (*Select) Eval

func (s *Select) Eval(ctx Context) (string, error)

Jump to

Keyboard shortcuts

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