Make WordPress Core

Opened 5 years ago

Last modified 2 years ago

#10373 reopened defect (bug)

Proper number formatting related to i18n

Reported by: honza.skypala Owned by: westi
Milestone: Future Release Priority: normal
Severity: normal Version: 2.8.1
Component: I18N Keywords: has-patch reporter-feedback
Focuses: Cc:


Hi there,

Technical description of the situation: WordPress function number_format_i18n() uses native PHP function number_format() for formatting numbers. Unfortunately this PHP function is not able to handle separators (both decimal and thousands separators) that fall into one of the following categories:

  • separator would contain more than one char, e.g. " "; in this case only the first char from the supplied string is used, in the example given above it would be "&".
  • separator is ASCII > 128, e.g. ASCII 160;

Impact: Although this is not a native bug to WordPress, the problem source is in PHP, the impact is caused also in WordPress. This situation is problematic for users in Eastern Europe (Czech Republic, Russia, etc.) where the standard thousands separator is " " (space). The users in these countries usually don't want to use real space (ASCII 32) as thousands separator, as it could be word wrapped and the number would be saparated into two lines. Unfortunatelly supplying both variants of non-breakable space (i.e. " " or ASCII 160) fails.

Proposed solution: unforunatelly this bug is reported in PHP for years and nothing happens there. Because of this situation I suggest fixing such problem in the next level, i.e. in WordPress. This means to create a custom function for formatting numbers, with identical input params as number_format(), just that this one would be able to handle separator types mentioned above.

I have such change already deployed on my WordPress blog for several months, so I am going to attach a diff file for the latest SVN state dealing with this issue.


Attachments (1)

functions.php.diff (2.4 KB) - added by honza.skypala 5 years ago.
Diff solving the issue described in the ticket.

Download all attachments as: .zip

Change History (20)

honza.skypala5 years ago

Diff solving the issue described in the ticket.

comment:1 Denis-de-Bernardy5 years ago

Given the very specific nature of the problem it might make more sense to just do:

$number = str_replace(' ', ' ', $number);

where we use it...

comment:2 Denis-de-Bernardy5 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 2.9

comment:3 ryan4 years ago

  • Milestone changed from 2.9 to Future Release

comment:4 westi4 years ago

  • Cc westi added

comment:5 westi4 years ago

Cross reference #10555

comment:6 hakre4 years ago

  • Milestone changed from Future Release to 3.0

comment:7 westi4 years ago

  • Owner changed from nbachiyski to westi
  • Status changed from new to accepted

comment:8 follow-up: nbachiyski4 years ago

I agree with Denis that in this specific case translators should add a number_format_i18n filter in the <locale>.php file and fix the problem there. I vote for wontfix.

comment:9 nbachiyski4 years ago

  • Resolution set to wontfix
  • Status changed from accepted to closed

comment:10 nacin4 years ago

  • Milestone 3.0 deleted

comment:11 nbachiyski4 years ago

One day I will start deleting milestones, too.

comment:12 in reply to: ↑ 8 pavelevap4 years ago

  • Cc pavelevap@… added

Replying to nbachiyski:

I agree with Denis that in this specific case translators should add a number_format_i18n filter in the <locale>.php file and fix the problem there. I vote for wontfix.

What do you mean by <locale>.php file?

comment:13 nbachiyski4 years ago

If you put a php file named after your locale in wp-content/languages/ it will be loaded automatically if the current locale matches the basename of the php file.

You can use it like a locale-specific plugin.

comment:14 pavelevap4 years ago

OK, thank you. So, my file will be cs_CZ.php and it works the same way as usual plugin? Any required header? Is it documented somewhere? And one more question - how can I distribute it with translated Czech version? Can I insert it to dist folder, for example http://svn.automattic.com/wordpress-i18n/cs_CZ/trunk/dist/? In dist folder I will create folder structure with this file dist/wp-content/languages/cs_CS.php? Thank you very much for your answers...

comment:15 nbachiyski4 years ago

Yes, it works like a plugin. You don't need anything special. Putting it in dist/ is perfcetly fine. Here is mine, for example:


comment:16 pavelevap4 years ago

Great. I was not sure... Thank you for your help!

comment:17 lkraav2 years ago

  • Cc lkraav added

comment:18 nacin2 years ago

  • Keywords reporter-feedback added; number formating i18n removed
  • Milestone set to Future Release
  • Resolution wontfix deleted
  • Status changed from closed to reopened

PHP 5.4.0 allows multiple bytes to be used for decimal points and thousands separators. Of course, we won't have 5.4.0 as a minimum version requirement for probably a decade. I am re-opening this to reflect our decision to begin incorporating locale-specific changes in core. (#19603, others.)

Which locales specifically need multiple characters to properly represent numbers?

comment:19 pavelevap2 years ago

For example Czech and probably also other languages with "space" as thousands separator (non-breakable space needed).

Note: See TracTickets for help on using tickets.