Documentation ¶
Overview ¶
Package lang provides template functions for content internationalization.
Index ¶
- type Namespace
- func (ns *Namespace) FormatAccounting(precision, currency, number any) (string, error)
- func (ns *Namespace) FormatCurrency(precision, currency, number any) (string, error)
- func (ns *Namespace) FormatNumber(precision, number any) (string, error)
- func (ns *Namespace) FormatNumberCustom(precision, number any, options ...any) (string, error)
- func (ns *Namespace) FormatPercent(precision, number any) (string, error)
- func (ns *Namespace) Merge(p2, p1 any) (any, error)
- func (ns *Namespace) Translate(ctx context.Context, id any, args ...any) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace provides template functions for the "lang" namespace.
func New ¶
func New() *Namespace
New returns a new instance of the lang-namespaced template functions.
func (*Namespace) FormatAccounting ¶
FormatAccounting returns the currency representation of number for the given currency and precision for the current language in accounting notation.
The return value is formatted with at least two decimal places.
func (*Namespace) FormatCurrency ¶
FormatCurrency returns the currency representation of number for the given currency and precision for the current language.
The return value is formatted with at least two decimal places.
func (*Namespace) FormatNumber ¶
FormatNumber formats number with the given precision for the current language.
func (*Namespace) FormatNumberCustom ¶
FormatNumberCustom formats a number with the given precision. The first options parameter is a space-delimited string of characters to represent negativity, the decimal point, and grouping. The default value is `- . ,`. The second options parameter defines an alternate delimiting character.
Note that numbers are rounded up at 5 or greater. So, with precision set to 0, 1.5 becomes `2`, and 1.4 becomes `1`.
For a simpler function that adapts to the current language, see FormatNumber.
func (*Namespace) FormatPercent ¶
FormatPercent formats number with the given precision for the current language. Note that the number is assumed to be a percentage.