localize ordinal numbers

2019-04-28 19:49发布

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条回答
乱世女痞
2楼-- · 2019-04-28 20:35

Not that I know of, but you can use NumberFormatter

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

Source:

查看更多
登录 后发表回答