Skip to main content
Version: 2.14.1

Configuration basics

Orientation

Prefer per-call culture arguments when an overload provides one. Use CultureInfo.CurrentCulture and CurrentUICulture when a Humanizer API follows ambient application culture. In this 2.x release, global configuration lives under Humanizer.Configuration; reserve Configurator for application-wide strategies, registries, or enum metadata rules.

Configure global behavior once during application startup, before any request or background worker can use Humanizer.

Example

This verified example installs the built-in precision date strategy at startup and proves the resulting output with an injected comparison instant:

Program.cs
using System.Globalization;
using Humanizer;
#if HUMANIZER_V2
using Humanizer.Configuration;
using Humanizer.DateTimeHumanizeStrategy;
#endif

var culture = CultureInfo.GetCultureInfo("en-US");
var comparison = new DateTime(2025, 1, 20, 12, 0, 0, DateTimeKind.Utc);

Configurator.DateTimeHumanizeStrategy =
new PrecisionDateTimeHumanizeStrategy(precision: 0.75);

var result = comparison.AddMinutes(-45).Humanize(
utcDate: true,
dateToCompareAgainst: comparison,
culture: culture);

if (result != "an hour ago")
throw new InvalidOperationException($"Unexpected result: {result}");

Console.WriteLine(result);

For a global date strategy, assign Configurator.DateTimeHumanizeStrategy once at startup. For a custom localized component, call the relevant registry's Register method before the registry is resolved.

Pitfall

This 2.x release keeps LocaliserRegistry<T> registrations mutable and exposes an assignable Configurator.EnumDescriptionPropertyLocator. Late changes are allowed, but process-wide configuration can still make concurrent requests observe different behavior. Configure it once during startup.

Version notes

The selected package predates registry freezing and the Humanizer 3 enum-locator method. Date strategies are under the 2.x strategy namespaces shown by the selected-version API. Confirm that API before adopting another global extension point.