getkirby / ideas

This is the backlog of ideas and feature requests from the last two years. Use our new feedback platform to post your new ideas or vote on existing ideas.
https://feedback.getkirby.com
20 stars 0 forks source link

`I18n::translateCount()`: format numbers based on the locale #474

Closed neildaniels closed 3 years ago

neildaniels commented 4 years ago

Currently, I18n::translateCount() merely sticks in an integer in place of the translation string. This is okay, but seems primitive for numbers >= 1000.

For example, There are 1,234 issues. looks much more natural than There are 1234 issues..

The translateCount() function should do this sort of formatting (probably via number_format()).

It should also take into account the current Kirby language/locale to ensure proper formatting. For example, in French the thousands separator would be a space, so it would be something like Il y a 1 234 problèmes.

The localeconv() function might be helpful here to pull the correct thousands separator.

neildaniels commented 4 years ago

Actually, the NumberFormatter class seems the easier to use.

$formatter = new NumberFormatter($kirby->language()->locale(LC_NUMERIC), NumberFormatter::DECIMAL);
echo $formatter->format(1234);
lukasbestle commented 3 years ago