开发者

localize ordinal numbers

开发者 https://www.devze.com 2022-12-22 21:26 出处:网络
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:

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 el开发者_开发问答se?

Thank you.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号