lang

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package lang provides template functions for content internationalization.

Index

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(deps *deps.Deps, translator locales.Translator) *Namespace

New returns a new instance of the lang-namespaced template functions.

func (*Namespace) FormatAccounting added in v1.0.0

func (ns *Namespace) FormatAccounting(precision, currency, number any) (string, error)

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 added in v1.0.0

func (ns *Namespace) FormatCurrency(precision, currency, number any) (string, error)

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 added in v1.0.0

func (ns *Namespace) FormatNumber(precision, number any) (string, error)

FormatNumber formats number with the given precision for the current language.

func (*Namespace) FormatNumberCustom added in v1.0.0

func (ns *Namespace) FormatNumberCustom(precision, number any, options ...any) (string, error)

FormatNumberCustom formats a number with the given precision using the negative, decimal, and grouping options. The `options` parameter is a string consisting of `<negative> <decimal> <grouping>`. The default `options` value is `- . ,`.

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 added in v1.0.0

func (ns *Namespace) FormatPercent(precision, number any) (string, error)

FormatPercent formats number with the given precision for the current language. Note that the number is assumed to be a percentage.

func (*Namespace) Merge added in v0.38.1

func (ns *Namespace) Merge(p2, p1 any) (any, error)

Merge creates a union of pages from two languages.

func (*Namespace) NumFmt

func (ns *Namespace) NumFmt(precision, number any, options ...any) (string, error)

NumFmt is deprecated, use FormatNumberCustom. We renamed this in Hugo 0.87. Deprecated: Use FormatNumberCustom

func (*Namespace) Translate

func (ns *Namespace) Translate(id any, args ...any) (string, error)

Translate returns a translated string for id.

Jump to

Keyboard shortcuts

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