localize ordinal numbers

纵饮孤独 提交于 2019-12-22 05:17:11

问题


for ($rank=0; $rank<100; $rank++) { printf("Your rank: %d%s", $rank, $suffix); }

Does there exist a gettext function to localize $suffix to the current language and return, for example:

Your rank: 0th
Your rank: 1st
Your rank: 2nd
Your rank: 3rd
Your rank: 4th

if the current locale is English, and whatever the correct "ordinal" forms of numbers are in other languages when the locale is set to something else?

Thank you.


回答1:


Not that I know of, but you can use NumberFormatter

$nf = new NumberFormatter('en_US', NumberFormatter::ORDINAL);
print $nf->format(123); // prints 123rd

Source:

  • Internationalization in PHP 5.3


来源:https://stackoverflow.com/questions/2453594/localize-ordinal-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!