Opened 4 weeks ago
Last modified 4 weeks ago
#7959 new defect (bug)
Changing thousands separator on download counter page
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | low | |
Component: | WordPress.org Site | Keywords: | has-patch |
Cc: |
Description
I have noticed the following with https://wordpress.org/download/counter/ for some time now:
When loading for the first time, the number is displayed with a comma as a thousands separator. Example:
7,438,998
As soon as the AJAX request for updating runs, it is suddenly a point as a separator. Example:
7.439.094
You probably have to open the page with a non-English browser to reproduce this, especially if the language uses thousands separators other than “,”.
I would have liked to offer a solution for this directly, but I am unsure how this is done in wporg-main-2022.
I assume (!) the AJAX request already does it correctly. Here the function https://developer.wordpress.org/reference/functions/number_format_i18n/ is used which uses the language-specific “thousands_sep”. Since I have a German-language browser, I assume (!) that the dot is used in the AJAX request. If this is the case, the problem would rather be the initial call of the page, which uses exactly the same function: https://github.com/WordPress/wporg-main-2022/blob/trunk/source/wp-content/themes/wporg-main-2022/src/download-counter/index.php#L41
My assumption is therefore: in one of the two cases, $wp_locale is not set, which results in the difference.
Change History (3)
#2
@
4 weeks ago
Yes, it's exactly the same URL for me. I have just tested this in the private browser window: it works there (the thousand separators remain on “,” and do not become “.”).
So I now see a connection with my login at wordpress.org. You can select a language in the forum profile. It is set to German for me. If I change it to English, the thousand points no longer change. If I change it back to German, they change again.
So the question for me is how why the thousand separators are wrong when the page is first loaded? In my case they should be on “.”, not on “,” if I load it with German as language in forum profile. Or?
#3
@
4 weeks ago
- Keywords has-patch added
So the question for me is how why the thousand separators are wrong when the page is first loaded?
When the page is first loaded, it uses the site's locale for number_format_i18n
, which is English here, so it loads with commas. If you go to https://es.wordpress.org/download/counter/, it will load initially with dots. The subsequent updates are pulled from the API which uses the user locale as @Otto42 mentioned, which is why it changes to dots for you (just like the Spanish site changes to commas for me).
I've got a PR to fix that here: https://github.com/WordPress/wporg-main-2022/pull/555
You can use the browser inspector to see the request from your browser. In my case, it is
https://wordpress.org/wp-json/wporg/v1/core-downloads/6.8?_locale=user
The code that does this is in wporg-main-2022/src/download-conter/index.php and yes, it uses the number_format_i18n call.
Now, the _locale parameter in the URL being set to 'user' triggers WordPress to call the get_user_locale function. From there, of course, the translation system does its thing and loads in the separators and such.