Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
Bundle represents a collection of messages and terms collected from one or many resources. It provides the main API to format messages.
func (*Bundle) AddResource ¶
AddResource adds a Resource to the Bundle. If a message or term was already defined by another resource, an error is raised and the entry is skipped.
func (*Bundle) AddResourceOverriding ¶
AddResourceOverriding adds a Resource to the Bundle. If a message or term was already defined by another resource, the already existing one gets overridden.
func (*Bundle) FormatMessage ¶
func (bundle *Bundle) FormatMessage(key string, contexts ...*FormatContext) (string, []error, error)
FormatMessage formats the message with the given key. To pass variables or functions, pass contexts created using WithVariable, WithVariables, WithFunction or WithFunctions. Besides the formatted message, this method returns the errors the resolver stumbled upon during resolving specific values and an optional error if there is no message with the given key. If the resolver returns errors it does not automatically mean that the whole message could not be resolved. It may be just incomplete.
type FormatContext ¶
type FormatContext struct {
// contains filtered or unexported fields
}
A FormatContext holds variables and functions to pass them to Bundle.FormatMessage
func WithFunction ¶
func WithFunction(key string, function Function) *FormatContext
WithFunction creates a FormatContext with a single function
func WithFunctions ¶
func WithFunctions(functions map[string]Function) *FormatContext
WithFunctions creates a FormatContext with multiple functions
func WithVariable ¶
func WithVariable(key string, value interface{}) *FormatContext
WithVariable creates a FormatContext with a single variable
func WithVariables ¶
func WithVariables(variables map[string]interface{}) *FormatContext
WithVariables creates a FormatContext with multiple variables
type NoValue ¶
type NoValue struct {
// contains filtered or unexported fields
}
NoValue is used whenever no "real" value could be built
type NumberValue ¶
type NumberValue struct {
Value float32
}
NumberValue wraps a number (float32 at the moment) in order to comply with the Value API
func Number ¶
func Number(val float32) *NumberValue
Number returns a new NumberValue with the given value; used for variables
func (*NumberValue) String ¶
func (value *NumberValue) String() string
String formats a NumberValue into a string
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource represents a collection of messages and terms extracted out of a FTL source
func NewResource ¶
NewResource parses the given source string and assembles its entries into a new Resource object. Besides the Resource object, this method also returns all errors the parser stumbled upon during parsing. As long as Resource.IsEmpty does not return false, at least something could be parsed successfully.
type StringValue ¶
type StringValue struct {
Value string
}
StringValue wraps a string in order to comply with the Value API
func String ¶
func String(val string) *StringValue
String returns a new StringValue with the given value; used for variables
func (*StringValue) String ¶
func (value *StringValue) String() string
String returns the wrapped value of a StringValue