Skip to content

[12.x] Add App::shouldSyncLocale() to keep helpers in line with the app locale #55326

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

Closed
wants to merge 2 commits into from

Conversation

CasEbb
Copy link

@CasEbb CasEbb commented Apr 8, 2025

When using the Number helper it is possible to specify the locale. The locale's default however, is always English and doesn't change when the app's locale changes. Carbon however, does do this. This leads to the awkward situation where Carbon returns localized results (where applicable), where Number doesn't.

<?php

app()->getLocale(); // "en"
now()->diffForHumans(); // "0 seconds ago"
Number::forHumans(1000); // "1 thousand"

app()->setLocale('nl');
now()->diffForHumans(); // "0 seconden geleden" 🇳🇱 👍
Number::forHumans(1000); // "1 thousand" 🇺🇸 🤔

Carbon's service provider listens for the LocaleUpdated event and updates its locale accordingly. This PR proposes a convience method to the Application class to do the same, as enabling this behaviour by default could be considered as a breaking change. Enabling this behaviour by default may be interesting for the next major version.

@CasEbb CasEbb changed the title [12.xAdd App::shouldSyncLocale() to keep helpers in line with the app locale [12.x] Add App::shouldSyncLocale() to keep helpers in line with the app locale Apr 8, 2025
@CasEbb CasEbb marked this pull request as draft April 8, 2025 20:04
@CasEbb CasEbb marked this pull request as ready for review April 8, 2025 20:13
@taylorotwell
Copy link
Member

Hey @CasEbb - it's a breaking change for us to change the contract on a patch release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants