Question

Paging Jay Querido...

Downloaded the Pluralizer NuGet package. My goal is to display a string like so:

X contracts with Y partners in Z countries

If X is 1, word should change to contract. If Z is 1, word should change to country. Same for 1 partner.

The following does not work. It always results in TotalContracts being the same number for the whole sentence.

@Html.Pluralize("{_} {contract} with {_} {partner} in {_} {country}",
    Model.TotalContracts, Model.TotalPartners, Model.TotalCountries)
@* result is X contracts with X partners in X countries *@

The following does work, but is not quite as readable. Is there a better way?

@Html.Pluralize("{_} {contract}", Model.TotalContracts) with
@Html.Pluralize("{_} {partner}", Model.TotalPartners.Count) in
@Html.Pluralize("{_} {country}", Model.TotalCountries)
Was it helpful?

Solution

It looks like my comment obscured an underscore. This works with a single call to Pluralize:

@Html.Pluralize("{0|_} {0|contract} with {1|_} {1|partner} in {2|_} {country}",
    Model.TotalContracts, Model.TotalPartners, Model.TotalCountries)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top