2

How can I singularize or pluralize a string with the words is or are based on a collection size. For example I would like to notify users about a conflict in a scheduling, And there could be 1 or more conflicts. So based on the amount of conflicts I would like to Humanize the string.

e.g When there is 1 conflict I would like to show There is {#} conflicting schedule.

e.g When there are more then 1. I would like to say There are {#} conflicting schedules.

You can see the 2 differences between the strings are the words Are/is and S at the end of schedules

Y Neuhaus
  • 84
  • 1
  • 6

1 Answers1

3

There might be a cleaner way to do it with Humanizer but I haven't found it. This works though:

$"There {"are".ToQuantity(qty, ShowQuantityAs.None)} {qty} conflicting {"schedule".ToQuantity(qty, ShowQuantityAs.None)}."
Steve Dowling
  • 1,919
  • 1
  • 13
  • 18