Humanizer
Humanizer copied to clipboard
Pluralize / singularize verbs?
Are ubiquitous verbs on the horizon? This could make so many programs "sound" friendlier:
string PeopleInLinePhrase(int numberOfPeople) {
int x = numberOfPeople;
return string.Format(
"There {0} {1} {2} in line ahead of you",
"is".ToQuantity(x),
x,
"person".ToQuantity(x));
// result (maintains given capitalization of "is" and "person"):
// x = 0: "are no people"
// x = 1: "is 1 person"
// x > 1: "are x people"
}
Regardless what the answer is, thanks for publishing this fantastic and eminently usable project!
English rules have proven rather complex to add to the library in the past (although not quite the same use case). To be honest with you I'm not sure when no
should be used instead of 0
. For is
and are
there is a relatively easy hack to make it work. Although not grammatically correct, we can add them to the reflector dictionary.
Small nitpicking: "person".ToQuantity(x)
prefixes the word with the number; e.g. 2 people
.
P.S. Thanks for the kind words. Glad you like it.
This would be cool. I currently use the following to handle this:
public static string SelectVerbByQuantity( int quantity, string singular, string plural ) => quantity == 1 ? singular : plural;