mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
@@ -43,8 +43,8 @@ type Namespace struct {
|
||||
}
|
||||
|
||||
// Translate returns a translated string for id.
|
||||
func (ns *Namespace) Translate(id interface{}, args ...interface{}) (string, error) {
|
||||
var templateData interface{}
|
||||
func (ns *Namespace) Translate(id any, args ...any) (string, error) {
|
||||
var templateData any
|
||||
|
||||
if len(args) > 0 {
|
||||
if len(args) > 1 {
|
||||
@@ -62,7 +62,7 @@ func (ns *Namespace) Translate(id interface{}, args ...interface{}) (string, err
|
||||
}
|
||||
|
||||
// FormatNumber formats number with the given precision for the current language.
|
||||
func (ns *Namespace) FormatNumber(precision, number interface{}) (string, error) {
|
||||
func (ns *Namespace) FormatNumber(precision, number any) (string, error) {
|
||||
p, n, err := ns.castPrecisionNumber(precision, number)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -72,7 +72,7 @@ func (ns *Namespace) FormatNumber(precision, number interface{}) (string, error)
|
||||
|
||||
// FormatPercent formats number with the given precision for the current language.
|
||||
// Note that the number is assumed to be a percentage.
|
||||
func (ns *Namespace) FormatPercent(precision, number interface{}) (string, error) {
|
||||
func (ns *Namespace) FormatPercent(precision, number any) (string, error) {
|
||||
p, n, err := ns.castPrecisionNumber(precision, number)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -84,7 +84,7 @@ func (ns *Namespace) FormatPercent(precision, number interface{}) (string, error
|
||||
// for the current language.
|
||||
//
|
||||
// The return value is formatted with at least two decimal places.
|
||||
func (ns *Namespace) FormatCurrency(precision, currency, number interface{}) (string, error) {
|
||||
func (ns *Namespace) FormatCurrency(precision, currency, number any) (string, error) {
|
||||
p, n, err := ns.castPrecisionNumber(precision, number)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -100,7 +100,7 @@ func (ns *Namespace) FormatCurrency(precision, currency, number interface{}) (st
|
||||
// for the current language in accounting notation.
|
||||
//
|
||||
// The return value is formatted with at least two decimal places.
|
||||
func (ns *Namespace) FormatAccounting(precision, currency, number interface{}) (string, error) {
|
||||
func (ns *Namespace) FormatAccounting(precision, currency, number any) (string, error) {
|
||||
p, n, err := ns.castPrecisionNumber(precision, number)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -112,7 +112,7 @@ func (ns *Namespace) FormatAccounting(precision, currency, number interface{}) (
|
||||
return ns.translator.FmtAccounting(n, p, c), nil
|
||||
}
|
||||
|
||||
func (ns *Namespace) castPrecisionNumber(precision, number interface{}) (uint64, float64, error) {
|
||||
func (ns *Namespace) castPrecisionNumber(precision, number any) (uint64, float64, error) {
|
||||
p, err := cast.ToUint64E(precision)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
@@ -139,7 +139,7 @@ func (ns *Namespace) castPrecisionNumber(precision, number interface{}) (uint64,
|
||||
// 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 (ns *Namespace) FormatNumberCustom(precision, number interface{}, options ...interface{}) (string, error) {
|
||||
func (ns *Namespace) FormatNumberCustom(precision, number any, options ...any) (string, error) {
|
||||
prec, err := cast.ToIntE(precision)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -240,16 +240,16 @@ func (ns *Namespace) FormatNumberCustom(precision, number interface{}, options .
|
||||
// NumFmt is deprecated, use FormatNumberCustom.
|
||||
// We renamed this in Hugo 0.87.
|
||||
// Deprecated: Use FormatNumberCustom
|
||||
func (ns *Namespace) NumFmt(precision, number interface{}, options ...interface{}) (string, error) {
|
||||
func (ns *Namespace) NumFmt(precision, number any, options ...any) (string, error) {
|
||||
return ns.FormatNumberCustom(precision, number, options...)
|
||||
}
|
||||
|
||||
type pagesLanguageMerger interface {
|
||||
MergeByLanguageInterface(other interface{}) (interface{}, error)
|
||||
MergeByLanguageInterface(other any) (any, error)
|
||||
}
|
||||
|
||||
// Merge creates a union of pages from two languages.
|
||||
func (ns *Namespace) Merge(p2, p1 interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Merge(p2, p1 any) (any, error) {
|
||||
merger, ok := p1.(pagesLanguageMerger)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("language merge not supported for %T", p1)
|
||||
|
Reference in New Issue
Block a user