Skip to main content
Version: 2.13.14

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;
using Humanizer.Inflections;

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));
AssertEqual("minus one people", "person".ToQuantity(-1, 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

Humanizer.Inflections.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. In Humanizer 2, only positive 1 selects the singular form; -1 is plural.

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 here under the Humanizer.Inflections namespace. Humanizer 3 consolidates the namespace and changes negative-one quantity behavior.