plurr

package
v0.0.0-...-cd773e1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT, MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyListOfVariants = errors.New("Empty list of variants")

ErrEmptyListOfVariants is returned by Format function in strict mode when choice block has no variants ("{X:}")

View Source
var ErrEmptyPlaceholderName = errors.New("Empty placeholder name")

ErrEmptyPlaceholderName is returned by Format function in strict mode when placeholder name is empty in the template string ("{}")

View Source
var ErrUnmatchedClosingBrace = errors.New("Unmatched } found")

ErrUnmatchedClosingBrace is returned by Format function when there's an unmateched closing curly brace in the template string

View Source
var ErrUnmatchedOpeningBrace = errors.New("Unmatched { found")

ErrUnmatchedOpeningBrace is returned by Format function when there's an unmateched opening curly brace in the template string

Functions

func SplitString

func SplitString(s string, start, end rune) []string

SplitString splits the `s` string by `start` and `end` delimiter runes and returns an array of strings including the delimiters

Types

type CallbackFunc

type CallbackFunc func(s string) (string, error)

CallbackFunc defines a type of callback function that is called to dynamically get the value of placeholder

type Params

type Params map[string]interface{}

Params type is used to pass placeholder values to Format function

type PlaceholderValueNotDefinedError

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

ErrPlaceholderValueNotDefined is returned by Format function when neither palaceholder not its prefix variant (sans '_PLURAL') is not defined

func (*PlaceholderValueNotDefinedError) Error

type Plurr

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

Plurr object

func New

func New() *Plurr

New initializes Plurr object

func (*Plurr) Format

func (p *Plurr) Format(s string, params Params) (string, error)

Format renders the string based on the template and a list (map) of parameters

func (*Plurr) SetAutoPlurals

func (p *Plurr) SetAutoPlurals(value bool) *Plurr

SetAutoPlurals sets the 'auto-plurals' mode where the value of 'X_PLURAL' placeholder is calculated automatically by taking the value of 'X' placeholder and passing it through `pluralFunc()`. This mode is enabled by default. Function returns the Plurr object so that calls can be chained.

func (*Plurr) SetCallback

func (p *Plurr) SetCallback(value CallbackFunc) *Plurr

SetCallback sets the callback function to be called by 'plurr.Format' to get placeholder values dynamically. Function returns the Plurr object so that calls can be chained.

func (*Plurr) SetLocale

func (p *Plurr) SetLocale(locale string) *Plurr

SetLocale chooses the plural function based on locale name. Function returns the Plurr object so that calls can be chained.

func (*Plurr) SetStrict

func (p *Plurr) SetStrict(value bool) *Plurr

SetStrict sets the 'strict' mode where missing placeholder values, as well as non-uint values of placeholders about to be passed through a plural function, are reported as errors. This mode is enabled by default. Function returns the Plurr object so that calls can be chained.

type ValueNotAnIntegerError

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

ErrValueNotAnInteger is returned by Format function in strict mode when placeholder value can't be evaluated to 0 or positive integer

func (*ValueNotAnIntegerError) Error

func (e *ValueNotAnIntegerError) Error() string

type ValueNotDefinedError

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

ErrValueNotDefined is returned by Format function in strict mode when placeholder value is not provided in the parameters map

func (*ValueNotDefinedError) Error

func (e *ValueNotDefinedError) Error() string

Jump to

Keyboard shortcuts

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