Home

Awesome

GitHub license Build status Coverage Status NuGet NuGet

What is it?

This is a C# port of Blake Embrey's pluralize library which helps in pluralizing or singularizing any English word.

Changes reflect commits up to https://github.com/blakeembrey/pluralize/commit/0265e4d131ecad8e11c420fa4be98b75dc92c33d from May 25, 2019.

Why

I could not find a good C# alternative for converting words from singular to plural and vice versa. System.Data.Entity.Design.PluralizationServices.PluralizationService and Humanizer library did not meet the expectations (try 'shoes' or 'toes'). However this small but awesome Javascript libray pluralize worked very well for me and I decided to convert the code to C# and use it.

How

Install from NuGet

Using Package manager console

Install-Package Pluralize.NET

Using dotnet CLI

dotnet add package Pluralize.NET

Using paket CLI

paket add Pluralize.NET

Include using directive

using Pluralize.NET

Write code

IPluralize pluralizer = new Pluralizer();

pluralizer.Singularize("Horses");  //=> "Horse"
pluralizer.Pluralize("Horse");  //=> "Horses"

// Example of new plural rule:
pluralizer.Pluralize("regex"); //=> "regexes"
pluralizer.AddPluralRule(new Regex("gex$"), "gexii");
pluralizer.Pluralize("regex"); //=> "regexii"

// Example of new singular rule:
pluralizer.Singularize('singles'); //=> "single"
pluralizer.AddSingularRule(new Regex("singles"), 'singular');
pluralizer.Singularize('singles'); //=> "singular"

// Example of new irregular rule, e.g. "I" -> "we":
pluralizer.Pluralize('irregular'); //=> "irregulars"
pluralizer.AddIrregularRule('irregular', 'regular');
pluralizer.Pluralize('irregular'); //=> "regular"

// Example of uncountable rule (rules without singular/plural in context):
pluralizer.Pluralize('paper'); //=> "papers"
pluralizer.AddUncountableRule('paper');
pluralizer.Pluralize('paper'); //=> "paper"

// Example of asking whether a word looks singular or plural:
pluralizer.IsPlural('test'); //=> false
pluralizer.IsSingular('test'); //=> true

// Example of formatting a word based on count
pluralizer.Format(5, "dog"); // => "dogs"
pluralizer.Format(5, "dog", inclusive: true); // => "5 dogs"

Profit!

Supported .NET Versions

The Nuget package supports the following .NET versions. This pretty much covers versions 4.0 and above. Please open an issue if you want to support any .NET version in particular.

Licence

MIT - because the original project is MIT

Contributors ✨

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <td align="center"><a href="https://github.com/sarathkcm"><img src="https://avatars0.githubusercontent.com/u/14143311?v=4" width="100px;" alt=""/><br /><sub><b>Sarath Kumar CM</b></sub></a><br /><a href="https://github.com/sarathkcm/Pluralize.NET/commits?author=sarathkcm" title="Code">💻</a></td> <td align="center"><a href="https://www.linkedin.com/in/daniel-destouche/"><img src="https://avatars3.githubusercontent.com/u/2773690?v=4" width="100px;" alt=""/><br /><sub><b>Daniel Destouche</b></sub></a><br /><a href="https://github.com/sarathkcm/Pluralize.NET/commits?author=ghost1face" title="Code">💻</a></td> <td align="center"><a href="https://sorashi.github.io"><img src="https://avatars0.githubusercontent.com/u/6270283?v=4" width="100px;" alt=""/><br /><sub><b>Dennis Pražák</b></sub></a><br /><a href="https://github.com/sarathkcm/Pluralize.NET/commits?author=sorashi" title="Code">💻</a></td> </tr> </table> <!-- markdownlint-enable --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!