diff options
Diffstat (limited to 'tpl/lang/lang.go')
-rw-r--r-- | tpl/lang/lang.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tpl/lang/lang.go b/tpl/lang/lang.go index 491e2492e..4e6c9c70a 100644 --- a/tpl/lang/lang.go +++ b/tpl/lang/lang.go @@ -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 |