Humanizer icon indicating copy to clipboard operation
Humanizer copied to clipboard

Pluralize / singularize verbs?

Open piranout opened this issue 10 years ago • 2 comments

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!

piranout avatar Oct 24 '14 22:10 piranout

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.

MehdiK avatar Oct 24 '14 22:10 MehdiK

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;

dbmercer avatar Nov 04 '22 22:11 dbmercer