Humanizr/Humanizer · critical · InvalidOperationException

Locale '{localeCode}.surfaces.ordinal.date' must be a mappin

Error message

Locale '{localeCode}.surfaces.ordinal.date' must be a mapping, not a scalar or sequence.

What it means

Thrown by AddOrdinalFeatures when surfaces.ordinal.date is present but is not a YAML mapping. The 'date' surface (dateToOrdinalWords) must be a mapping, so scalar/sequence values fail the build.

Source

Thrown at src/Humanizer.SourceGenerators/Common/CanonicalLocaleAuthoring.cs:427

                    $"Locale '{localeCode}.surfaces.ordinal' defines unsupported property '{property}'. Supported properties: numeric, date, dateOnly.");
            }

            if (ordinalSurface.TryGetValue("numeric", out var numericValue))
            {
                if (numericValue is not SimpleYamlMapping numericMapping)
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.ordinal.numeric' must be a mapping, not a scalar or sequence.");
                }

                features["ordinalizer"] = numericMapping;
            }

            if (ordinalSurface.TryGetValue("date", out var dateValue))
            {
                if (dateValue is not SimpleYamlMapping dateMapping)
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.ordinal.date' must be a mapping, not a scalar or sequence.");
                }

                features["dateToOrdinalWords"] = dateMapping;
            }

            if (ordinalSurface.TryGetValue("dateOnly", out var dateOnlyValue))
            {
                if (dateOnlyValue is not SimpleYamlMapping dateOnlyMapping)
                {
                    throw new InvalidOperationException(
                        $"Locale '{localeCode}.surfaces.ordinal.dateOnly' must be a mapping, not a scalar or sequence.");
                }

                features["dateOnlyToOrdinalWords"] = dateOnlyMapping;
            }
        }

View on GitHub (pinned to ffc2b77c0f)

Solutions

  1. Rewrite surfaces.ordinal.date as a mapping matching the dateToOrdinalWords rule shape.
  2. Copy the structure from a reference locale (e.g. en.yml) and translate values.
  3. Rebuild to confirm AddOrdinalFeatures accepts the surface.

Example fix

# before
ordinal:
  date: on
# after
ordinal:
  date:
    1: first
Defensive patterns

Strategy: validation

Validate before calling

# Ensure surfaces.ordinal.date is a mapping, not a scalar/sequence.
# YAML lint: 'date:' must be followed by an indented mapping block.

Prevention

When it happens

Trigger: A locale YAML declares 'date: true' or 'date: [first, second]' under surfaces.ordinal. The type guard at CanonicalLocaleAuthoring.cs:425-429 fails because dateValue is not a SimpleYamlMapping.

Common situations: Treating 'date' as an enable flag; pasting a list of day ordinals; mis-indenting the block.

Related errors


AI-assisted analysis of Humanizr/Humanizer@ffc2b77c0f (2026-08-13). Data as JSON: /api/errors/b91854e1b2d5c610. Report an issue: GitHub.