mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
@@ -15,12 +15,13 @@
|
||||
package lang
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -39,12 +40,21 @@ type Namespace struct {
|
||||
|
||||
// Translate returns a translated string for id.
|
||||
func (ns *Namespace) Translate(id interface{}, args ...interface{}) (string, error) {
|
||||
var templateData interface{}
|
||||
|
||||
if len(args) > 0 {
|
||||
if len(args) > 1 {
|
||||
return "", errors.Errorf("wrong number of arguments, expecting at most 2, got %d", len(args)+1)
|
||||
}
|
||||
templateData = args[0]
|
||||
}
|
||||
|
||||
sid, err := cast.ToStringE(id)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return ns.deps.Translate(sid, args...), nil
|
||||
return ns.deps.Translate(sid, templateData), nil
|
||||
}
|
||||
|
||||
// NumFmt formats a number with the given precision using the
|
||||
|
Reference in New Issue
Block a user