Skip to main content
Version: 3.0.10 (latest)

Inflect nouns and render quantities

Orientation

Use Pluralize or Singularize when the application has an English noun but not a count. Use ToQuantity when the count and noun belong together. Humanizer’s vocabulary handles common irregular and uncountable English nouns; an application can add domain-specific rules before it begins formatting text.

Example

This isolated executable covers a built-in irregular noun, a quantity written as words, and one application-specific irregular pair:

Program.cs
using System.Globalization;
using Humanizer;

var culture = CultureInfo.GetCultureInfo("en-US");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;

AssertEqual("people", "person".Pluralize());
AssertEqual("person", "people".Singularize());
AssertEqual("two people", "person".ToQuantity(2, ShowQuantityAs.Words));

Vocabularies.Default.AddIrregular("cactoid", "cactoidae", matchEnding: false);
AssertEqual("cactoidae", "cactoid".Pluralize());
AssertEqual("cactoid", "cactoidae".Singularize());

Console.WriteLine("people; two people; cactoidae");

static void AssertEqual(string expected, string? actual)
{
if (actual != expected)
throw new InvalidOperationException($"Expected '{expected}', got '{actual}'.");
}

Tell Humanizer what the input means

Pluralize(inputIsKnownToBeSingular: false) avoids pluralizing an input that may already be plural. The matching Singularize flag avoids a second singularization. Singularize(skipSimpleWords: true) specifically skips the simple trailing-s rule for a one-word input; irregular and other configured rules still apply.

ToQuantity accepts:

  • ShowQuantityAs.None for only the correctly inflected noun.
  • ShowQuantityAs.Numeric for a formatted numeric count.
  • ShowQuantityAs.Words for a localized number word followed by the noun.

Numeric format strings and providers control the displayed number. They do not turn the English inflector into a localized noun engine.

Extend the vocabulary

Vocabularies.Default supports AddIrregular, AddUncountable, AddPlural, and AddSingular. Prefer an irregular or uncountable entry over a broad regular expression. Set matchEnding: false when a rule must match the entire noun instead of every word ending with the same letters.

Pitfall

Vocabulary changes are process-global. Register domain words once during startup and test them in an isolated process; do not add rules per request. ToQuantity treats exactly 1 and -1 as singular. Fractional values, NaN, and infinity use the plural form.

This API inflects English nouns. For localized number words and grammar-aware ordinals, use numbers in words and ordinals and check the culture capability table.

Version notes

Core inflection is available across the documented release set. Individual vocabulary rules and overloads have changed, and early Humanizer 3.0.x temporarily lacked quantity overloads restored by 3.0.8. The verified source runs against the selected package.