gohugoio/hugo · error
wrong number of arguments, expecting at most 2, got
Error message
wrong number of arguments, expecting at most 2, got %d
What it means
lang.Translate (the 'T' / i18n function) accepts an id and at most one templateData argument (two total). When more than one variadic arg is supplied, Translate rejects it. See lang.go:49-52.
Solutions
- Pass data as a single object: a struct, map (dict), or slice that the translation catalog can interpolate.
- Reduce to at most two total arguments (id + one templateData).
- Move multiple values into a single dict passed as templateData.
Example fix
// before
{{ T "welcome" .Name .Date }}
// after
{{ T "welcome" (dict "name" .Name "date" .Date) }} Defensive patterns
Strategy: validation
Validate before calling
// Limit Translate to at most 2 total arguments.
if len(args) > 1 {
return "", fmt.Errorf("Translate accepts id plus at most one data arg, got %d", len(args)+1)
} Prevention
- Bundle multiple substitution values into a single dict passed as templateData.
- Remember T is not printf; it takes one optional data object, not variadic substitutions.
When it happens
Trigger: {{ T "welcome" .Name .Date }} passing three total arguments instead of two.
Common situations: Assuming Translate supports printf-style variadic substitution; refactoring a printf call into T and leaving extra positional args.
Related errors
- language merge not supported for %T
- must not provide more arguments than Resource and hash…
- must provide a Resource and optionally an options map
- must provide a Resource object
- must provide an URL and optionally an options map
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/d61e974be26a3428.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/lang/lang.go:51
return &Namespace{
translator: translator,
deps: deps,
}
}
// Namespace provides template functions for the "lang" namespace.
type Namespace struct {
translator golocales.Translator
deps *deps.Deps
}
// Translate returns a translated string for id.
func (ns *Namespace) Translate(ctx context.Context, id any, args ...any) (string, error) {
var templateData any
if len(args) > 0 {
if len(args) > 1 {
return "", fmt.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 "", err
}
return ns.deps.Translate(ctx, sid, templateData), nil
}
// FormatNumber formats number with the given precision for the current language.
func (ns *Namespace) FormatNumber(precision, number any) (string, error) {
p, n, err := ns.castPrecisionNumber(precision, number)
if err != nil {
return "", err
}View on GitHub (pinned to 52c9bd7908)