8000 Download counter: Set a locale to prevent the AJAX request from using the user's locale by ryelle · Pull Request #555 · WordPress/wporg-main-2022 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Download counter: Set a locale to prevent the AJAX request from using the user's locale #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

ryelle
Copy link
Contributor
@ryelle ryelle commented Apr 20, 2025

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 running number_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:

  1. With your site's language set to English
  2. View the download counter page /download/counter/
  3. Number loads with commas
  4. Change your user's language to a language with different thousands separators, for example Spanish, German.
  5. Number should still use commas even after new API requests

Optionally switch the site and user languages (Spanish for site, English for user), and ensure that the thousands separators stay consistent.

@ryelle ryelle added the [Component] Blocks Custom blocks or block variations label Apr 20, 2025
Copy link
Member
@dd32 dd32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this, but it looks good to me and expected.

@ryelle ryelle moved this to 👀 In review (PRs only) in WordPress.org May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Blocks Custom blocks or block variations
Projects
Status: 👀 In review (PRs only)
Development

Successfully merging this pull request may close these issues.

2 participants
0