I am building a multi-languages grails website and I need to get the ordinal suffix of a number for several languages like English, French, Spanish, German and Italian.
I believe that this issue is quite common for multi-languages website owners. I have found this article that provides a solution but it is English only.
For instance:
/**
*@value number
*@locale Current locale
*@returns ordinal suffix for the given number
**/
public static String getOrdinalFor(int value, Locale locale)
will give the following results:
assert getOrdinalFor(1, Locale.ENGLISH) == "st"
assert getOrdinalFor(1, Locale.FRENCH) == "er"
assert getOrdinalFor(2, Locale.ENGLISH) == "nd"
assert getOrdinalFor(3, Locale.ENGLISH) == "rd"
assert getOrdinalFor(4, Locale.ENGLISH) == "th"
assert getOrdinalFor(4, Locale.FRENCH) == "ème"
Do you know a library (in Java or Groovy) that can help this? Or do you know an algorithm that implements it?