{"record":{"id":"2f3f47249c31a9ea","repo":"kataras/iris","slug":"key-q-missing-plural-count-argument","errorCode":null,"errorMessage":"key: %q: missing plural count argument","messagePattern":"key: %q: missing plural count argument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"i18n/internal/message.go","lineNumber":77,"sourceCode":"// first argument should be a map. The map key resolves to the pluralization\n// of the message is the \"PluralCount\". And for variables the user\n// should set a message key which looks like: %VAR_NAME%Count, e.g. \"DogsCount\"\n// to set plural count for the \"Dogs\" variable, case-sensitive.\nfunc (m *Message) Render(args ...any) (string, error) {\n\tif m.Plural {\n\t\tif len(args) > 0 {\n\t\t\tif pluralCount, ok := findPluralCount(args[0]); ok {\n\t\t\t\tfor _, plural := range m.Plurals {\n\t\t\t\t\tif plural.Form.MatchPlural(pluralCount) {\n\t\t\t\t\t\treturn plural.Renderer.Render(args...)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn \"\", fmt.Errorf(\"key: %q: no registered plurals for <%d>\", m.Key, pluralCount)\n\t\t\t}\n\t\t}\n\n\t\treturn \"\", fmt.Errorf(\"key: %q: missing plural count argument\", m.Key)\n\t}\n\n\treturn m.Locale.Printer.Sprintf(m.Key, args...), nil\n}\n","sourceCodeStart":59,"sourceCodeEnd":82,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/i18n/internal/message.go#L59-L82","documentation":"For plural messages, Render extracts the plural count from args[0] via findPluralCount. If args is empty or args[0] is not a recognizable numeric count, it returns \"key: %q: missing plural count argument\". The message is registered as plural but was rendered without a count.","triggerScenarios":"Calling T/TR/Render on a plural key without any arguments, or with a first argument that is not a number (e.g. a map without a resolvable count where findPluralCount returns !ok).","commonSituations":"Developers forgetting to pass the count to a plural key, passing a struct/string first, or template-based plural messages whose map lacks the PluralCount entry.","solutions":["Pass the plural count as the first argument: T(\"apples\", n, ...).","For template plural messages, ensure the args[0] map contains \"PluralCount\" with a numeric value.","Check that the key really is plural in your translation files and whether a plain (non-plural) variant should be used instead.","Add a DefaultMessageFunc or wrapper that defaults the count to 1/other when absent."],"exampleFix":"// before\napp.I18n.Tr(ctx, \"apples\")\n// after\napp.I18n.Tr(ctx, \"apples\", 3)","handlingStrategy":"validation","validationCode":"// guard before rendering a plural key\nfunc renderPlural(tr Renderer, n int, args ...any) (string, error) {\n    if n < 0 {\n        return \"\", fmt.Errorf(\"plural count must be >= 0, got %d\", n)\n    }\n    return tr.Render(append([]any{n}, args...)...)\n}","typeGuard":"func hasPluralCount(args []any) bool {\n    if len(args) == 0 { return false }\n    switch args[0].(type) {\n    case int, int8, int16, int32, int64,\n         uint, uint8, uint16, uint32, uint64,\n         float32, float64:\n        return true\n    }\n    return false\n}","tryCatchPattern":"s, err := i18n.Tr(ctx, key)\nif err != nil && strings.Contains(err.Error(), \"missing plural count argument\") {\n    s, err = i18n.Tr(ctx, key, 1)\n}","preventionTips":["Always pass the count as the first argument to plural keys.","For template plurals, include \"PluralCount\" in the args[0] map.","Document which keys are plural so callers know to pass counts.","Wrap Tr in a helper that injects a default count."],"tags":["i18n","go","plural","arguments"],"backgroundTag":"missing-plural-count-argument","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}