{"id":"d61e974be26a3428","repo":"gohugoio/hugo","slug":"wrong-number-of-arguments-expecting-at-most-2-go","errorCode":null,"errorMessage":"wrong number of arguments, expecting at most 2, got %d","messagePattern":"wrong number of arguments, expecting at most 2, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/lang/lang.go","lineNumber":51,"sourceCode":"\treturn &Namespace{\n\t\ttranslator: translator,\n\t\tdeps:       deps,\n\t}\n}\n\n// Namespace provides template functions for the \"lang\" namespace.\ntype Namespace struct {\n\ttranslator golocales.Translator\n\tdeps       *deps.Deps\n}\n\n// Translate returns a translated string for id.\nfunc (ns *Namespace) Translate(ctx context.Context, id any, args ...any) (string, error) {\n\tvar templateData any\n\n\tif len(args) > 0 {\n\t\tif len(args) > 1 {\n\t\t\treturn \"\", fmt.Errorf(\"wrong number of arguments, expecting at most 2, got %d\", len(args)+1)\n\t\t}\n\t\ttemplateData = args[0]\n\t}\n\n\tsid, err := cast.ToStringE(id)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn ns.deps.Translate(ctx, sid, templateData), nil\n}\n\n// FormatNumber formats number with the given precision for the current language.\nfunc (ns *Namespace) FormatNumber(precision, number any) (string, error) {\n\tp, n, err := ns.castPrecisionNumber(precision, number)\n\tif err != nil {\n\t\treturn \"\", err\n\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/lang/lang.go#L33-L69","documentation":"Hugo's `lang.Translate` (template function `T`/`i18n`) accepts a translation id plus at most one optional template-data argument. This error is returned from `Namespace.Translate` in tpl/lang/lang.go when more than one variadic arg is passed after the id; the reported count is len(args)+1 to include the id itself.","triggerScenarios":"Calling `{{ T \"greeting\" .Data extraArg }}` or `{{ i18n \"key\" arg1 arg2 }}` — any invocation with three or more total arguments to the T/i18n/lang.Translate template function.","commonSituations":"Developers coming from other i18n systems that take multiple positional placeholders (e.g. printf-style) pass several values instead of one context object; or a pipeline accidentally appends an extra argument (`{{ .Title | i18n \"key\" .Params }}`).","solutions":["Pass at most one data argument: wrap multiple values in a dict, e.g. `{{ i18n \"key\" (dict \"Name\" .Name \"Count\" .Count) }}`.","In the i18n TOML/YAML file, reference the dict fields via Go template placeholders like `{{ .Name }}`.","If piping, remember the piped value counts as the last argument — restructure the call so only id + one data value reach T."],"exampleFix":"<!-- before -->\n{{ i18n \"welcome\" .Name .Count }}\n<!-- after -->\n{{ i18n \"welcome\" (dict \"Name\" .Name \"Count\" .Count) }}","handlingStrategy":"validation","validationCode":"{{/* lang.FormatNumber takes at most 2 args: precision, number */}}\n{{ $args := slice 2 1234.56 }}\n{{ if le (len $args) 2 }}{{ lang.FormatNumber 2 1234.56 }}{{ end }}","typeGuard":null,"tryCatchPattern":"{{ with try (lang.FormatNumber 2 1234.56 3) }}{{ with .Err }}{{ warnf \"%s\" . }}{{ else }}{{ .Value }}{{ end }}{{ end }}","preventionTips":["Call lang.* format functions with exactly (precision, number) or just (number) — never pass extra positional args","Check the Hugo docs signature before piping values, since piping adds the final argument implicitly","Avoid spreading user-built slices into function calls; construct the call explicitly"],"tags":["hugo","templates","i18n","go"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}