Download counter: Set a locale to prevent the AJAX request from using the user's locale #555
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By default, the API request will try to set the user's language before returning the number, which might be different than the site's language. For example, on the English site, the number initially loads with commas for thousands separators, but if someone with Spanish as their user-level language views the page, the API will use Spanish when formatting the number.
This is because the
apiFetch
command has a middleware that adds_locale=user
to requests, telling the API to load the user's locale when runningnumber_format_i18n
.The fix here is simple, adding
_locale=site
to prevent the middleware from adding the user value, and so keeping the request in the site's locale, like it is on the initial render.Fixes https://meta.trac.wordpress.org/ticket/7959
Props threadi, Otto42.
How to test the changes in this Pull Request:
/download/counter/
Optionally switch the site and user languages (Spanish for site, English for user), and ensure that the thousands separators stay consistent.