简体   繁体   中英

Humanizer Pluralize/Singularize to indicate Is/Are based on the collection size

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.

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

eg 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

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)}."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM