6

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.

gigawatt
  • 87
  • 1
  • 4
abernier
  • 27,030
  • 20
  • 83
  • 114

1 Answers1

7

Not that I know of, but you can use NumberFormatter

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

Source:

Willington Vega
  • 4,732
  • 3
  • 21
  • 19
Gordon
  • 312,688
  • 75
  • 539
  • 559
  • I don't know if I've discovered a bug in PHP or the Swedish language pack, but doing this for sv_SE or sv_FI for 1 returns "1:e%digits-ordinal-neutre:0: 1:a" Or am I missing an additional argument? – Lucent Aug 14 '10 at 13:30