langs/i18n: Upgrade to go-i18n v2

Fixes #5242
This commit is contained in:
Bjørn Erik Pedersen
2019-06-02 11:11:46 +02:00
parent 111344113b
commit 97987e5c02
7 changed files with 121 additions and 81 deletions

View File

@@ -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