kataras/iris · error

key: %q: missing plural count argument

Error message

key: %q: missing plural count argument

What it means

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.

Source

Thrown at i18n/internal/message.go:77

// first argument should be a map. The map key resolves to the pluralization
// of the message is the "PluralCount". And for variables the user
// should set a message key which looks like: %VAR_NAME%Count, e.g. "DogsCount"
// to set plural count for the "Dogs" variable, case-sensitive.
func (m *Message) Render(args ...any) (string, error) {
	if m.Plural {
		if len(args) > 0 {
			if pluralCount, ok := findPluralCount(args[0]); ok {
				for _, plural := range m.Plurals {
					if plural.Form.MatchPlural(pluralCount) {
						return plural.Renderer.Render(args...)
					}
				}

				return "", fmt.Errorf("key: %q: no registered plurals for <%d>", m.Key, pluralCount)
			}
		}

		return "", fmt.Errorf("key: %q: missing plural count argument", m.Key)
	}

	return m.Locale.Printer.Sprintf(m.Key, args...), nil
}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Pass the plural count as the first argument: T("apples", n, ...).
  2. For template plural messages, ensure the args[0] map contains "PluralCount" with a numeric value.
  3. Check that the key really is plural in your translation files and whether a plain (non-plural) variant should be used instead.
  4. Add a DefaultMessageFunc or wrapper that defaults the count to 1/other when absent.

Example fix

// before
app.I18n.Tr(ctx, "apples")
// after
app.I18n.Tr(ctx, "apples", 3)
Defensive patterns

Strategy: validation

Validate before calling

// guard before rendering a plural key
func renderPlural(tr Renderer, n int, args ...any) (string, error) {
    if n < 0 {
        return "", fmt.Errorf("plural count must be >= 0, got %d", n)
    }
    return tr.Render(append([]any{n}, args...)...)
}

Type guard

func hasPluralCount(args []any) bool {
    if len(args) == 0 { return false }
    switch args[0].(type) {
    case int, int8, int16, int32, int64,
         uint, uint8, uint16, uint32, uint64,
         float32, float64:
        return true
    }
    return false
}

Try / catch

s, err := i18n.Tr(ctx, key)
if err != nil && strings.Contains(err.Error(), "missing plural count argument") {
    s, err = i18n.Tr(ctx, key, 1)
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/2f3f47249c31a9ea. Report an issue: GitHub.