One penny, two pence - adding an
s to make it plural just won't cut it.
The singular plural variation is an annoyance that you’ve probably had to deal with many times.
So if you were populating a dashboard with users, you'd just call it like
pluralizer("user", "users") and that would be it. But language is an irrational field, and I've recently stumbled across this answer on StackOverflow, that reflects the intrinsics of different languages. In this particular case, Czech.
Java 11 has a handy construct called
ChoiceFormat that allows you to deal with this scenario in a very elegant way:
There is another project that’s a worthy mention, Evo Inflector.
It's based on the work of Damian Conway – “An Algorithmic Approach to English Pluralization” – and does wonders for most forms of the English language. But it’s an external dependency, more than often will be overkill and only covers ~70% of the words.
Link to Oracle’s ChoiceFormat documentation.
The problem above reminds me of CODE by Charles Petzold. If you can, I highly suggest you add it to your read-list. Dwells with the intricacies of all codes, written, spoken, drawn and, obviously, compiled.
As an Amazon Associate I may earn from qualifying purchases on some links.
If you found this page helpful, please share.