fluent

package
v0.0.0-...-914fd90 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 7 Imported by: 0

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 NewBundle

func NewBundle(primaryLocale language.Tag, fallbackLocales ...language.Tag) *Bundle

NewBundle creates a new empty bundle

func (*Bundle) AddResource

func (bundle *Bundle) AddResource(resource *Resource) (errs []error)

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

func (bundle *Bundle) AddResourceOverriding(resource *Resource)

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 Function

type Function func(positional []Value, named map[string]Value) Value

Function represents a function that builds a Value based on parameters

type NoValue

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

NoValue is used whenever no "real" value could be built

func (*NoValue) String

func (value *NoValue) String() string

String returns the NoValue's string representation

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

func NewResource(source string) (*Resource, []*parser.Error)

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.

func (*Resource) IsEmpty

func (resource *Resource) IsEmpty() bool

IsEmpty returns if no terms and no messages are present in the resource. This can be the case if the parser could not parse any valid messages and terms.

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

type Value

type Value interface {
	String() string
}

A Value is the result of a resolving operation performed by the Resolver. It represents either a string, a number or a date time.

Directories

Path Synopsis
ast

Jump to

Keyboard shortcuts

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