Pluralizing in ColdFusion

A few (ok, ten) years ago, I needed to generically pluralize English words in ColdFusion. Also, I wanted to be able to reverse that out ("singularize" as it were). This should be a really easy problem: If it ends with an "s" then add "es"; If it ends with a "y" then ditch the "y"; Otherwise just add "s". It turns out, though, that English is delightfully complicated.

So, Pluralizer.

I created it ten years ago, and I've used a fair number of times since. It isn't complicated enough that I've needed to update it much in that time.

Since it is doing something pretty simple, it is as easy to use as you'd expect.

Variables.Pluralizer = CreateObject("component","com.sebtools.Pluralizer").init();

plural = Variables.Pluralizer.pluralize(myword);

singular = Variables.Pluralizer.singularize(plural);

Most of the code is just a list of English exceptions to general rules. Expecially to allow "singularize".

Not much to it, but I've liked having it around so maybe someone else will get some use out of it.

Pluralizer is part of the com.sebtools package. It is a free ColdFusion package and you can read more about it in my com.sebtools blog series. Check it out!

If you need any help with com.sebtools, or ColdFusion in general, let me know.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Have you compared the results with other libraries? I use an inflector CFC and I see that some of the logic is different and their module has some additional string functions that may be beneficial.
https://github.com/TeamCFML/teamcfml-inflector
# Posted By James Moberg | 9/23/20 3:19 PM
James,

Sorry I missed your comment earlier. I haven't compared to other libraries. I didn't even know that one existed. Honestly, I think it looks better than mine. Very nice!
# Posted By Steve Bryant | 10/28/20 9:47 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.