项目作者: sarathkcm

项目描述 :
:blue_book: Pluralize or singularize any English word.
高级语言: C#
项目地址: git://github.com/sarathkcm/Pluralize.NET.git
创建时间: 2017-03-21T16:28:30Z
项目社区:https://github.com/sarathkcm/Pluralize.NET

开源协议:MIT License

下载


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.aspx) 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

  1. Install-Package Pluralize.NET

Using dotnet CLI

  1. dotnet add package Pluralize.NET

Using paket CLI

  1. paket add Pluralize.NET

Include using directive

  1. using Pluralize.NET

Write code

  1. IPluralize pluralizer = new Pluralizer();
  2. pluralizer.Singularize("Horses"); //=> "Horse"
  3. pluralizer.Pluralize("Horse"); //=> "Horses"
  4. // Example of new plural rule:
  5. pluralizer.Pluralize("regex"); //=> "regexes"
  6. pluralizer.AddPluralRule(new Regex("gex$"), "gexii");
  7. pluralizer.Pluralize("regex"); //=> "regexii"
  8. // Example of new singular rule:
  9. pluralizer.Singularize('singles'); //=> "single"
  10. pluralizer.AddSingularRule(new Regex("singles"), 'singular');
  11. pluralizer.Singularize('singles'); //=> "singular"
  12. // Example of new irregular rule, e.g. "I" -> "we":
  13. pluralizer.Pluralize('irregular'); //=> "irregulars"
  14. pluralizer.AddIrregularRule('irregular', 'regular');
  15. pluralizer.Pluralize('irregular'); //=> "regular"
  16. // Example of uncountable rule (rules without singular/plural in context):
  17. pluralizer.Pluralize('paper'); //=> "papers"
  18. pluralizer.AddUncountableRule('paper');
  19. pluralizer.Pluralize('paper'); //=> "paper"
  20. // Example of asking whether a word looks singular or plural:
  21. pluralizer.IsPlural('test'); //=> false
  22. pluralizer.IsSingular('test'); //=> true
  23. // Example of formatting a word based on count
  24. pluralizer.Format(5, "dog"); // => "dogs"
  25. 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.

  • .NET 4.0
  • .NET Standard 1.1
  • .NET 4.5.1
  • .NET 4.6
  • .NET Standard 2.0

Licence

MIT - because the original project is MIT

Contributors ✨








Sarath Kumar CM

💻

Daniel Destouche

💻

Dennis Pražák

💻

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