Skip to main content
Version: 4.0 (next)

Pluralize and singularize nouns

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 English 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;

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

Console.WriteLine($"Plural: {"person".Pluralize()}");
Console.WriteLine($"Quantity: {"person".ToQuantity(2, ShowQuantityAs.Words)}");
Console.WriteLine($"Custom plural: {"cactoid".Pluralize()}");
Output
Plural: people
Quantity: two people
Custom plural: cactoidae

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.

AddAcronym uses the same vocabulary to preserve the canonical casing of a domain acronym during string humanization. Registration is case-insensitive, but the registered spelling controls the output. Acronyms must contain letters only.

Configure vocabularies at startup

Vocabulary changes, including acronym registrations, 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.

Pluralize, Singularize, vocabulary, and ToQuantity pluralize and singularize English nouns.