{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/lang/lang.go#L33-L69","documentation":"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.","triggerScenarios":"{{ T \"welcome\" .Name .Date }} passing three total arguments instead of two.","commonSituations":"Assuming Translate supports printf-style variadic substitution; refactoring a printf call into T and leaving extra positional args.","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."],"exampleFix":"// before\n{{ T \"welcome\" .Name .Date }}\n\n// after\n{{ T \"welcome\" (dict \"name\" .Name \"date\" .Date) }}","handlingStrategy":"validation","validationCode":"// Limit Translate to at most 2 total arguments.\nif len(args) > 1 {\n    return \"\", fmt.Errorf(\"Translate accepts id plus at most one data arg, got %d\", len(args)+1)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["hugo","lang","i18n","template","arguments"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}