如何在Java或Groovy中获取许多语言的数字的序号后缀 [英] How to get the ordinal suffix of a number for many languages in Java or Groovy
问题描述
我正在构建一个多语言的 grails 网站,我需要获取多种语言的序号后缀,例如英语,法语,西班牙语,德语和意大利语。
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"
你知道一个库(Java或Groovy)这可以帮助吗?或者你知道一个实现它的算法?
Do you know a library (in Java or Groovy) that can help this? Or do you know an algorithm that implements it?
推荐答案
我认为在很多语言中这种方法是不可能的,因为他们根本没有概念可以由一些字母组成的序号作为扩展名。对于第一即德文,您只能写1。或erster/erste/erstes,具体取决于您所编号的属性。
I think in many languages this approach is impossible as they simply have no concept of ordinals that can be composed of a number with some letters as extension. For "1st" i.e. in german you can only either write "1." or "erster"/"erste"/"erstes" depending of genus of what you are numbering.
这篇关于如何在Java或Groovy中获取许多语言的数字的序号后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!