How to get plurality of noun?
In Ruby on Rails, this is plural and singular functions added to Ruby string class.
How can I implements plural and 开发者_如何转开发singular functions in Java?
Example:
"book" plural() => "books"
"books" singular => "book"
Assuming you want to cover the exception cases too (e.g. person => people) then the module that handles this in Ruby on Rails is called Inflector
. Take a look at this Inflector project on java.net for something similar in Java. From the project summary:
Inflector is a Java API for forming plurals of words. The library supports English spellings, and is locale-aware so it is straightforward to customize for any language.
Note: that I think this might only do singular => plural and not the other way around.
精彩评论