Skip to content

Commit 11097fe

Browse files
authored
[Core] set intl.default_locale (#10053)
The IntlDateFormatter in PHP uses the value of intl.default_locale, not \setlocale in order to decide on the formatting to use for dates when a null value/empty string is passed as the locale. This explicitly sets it so that dates in the en-CA locale are formatted as YYYY-mm-dd instead of YYYY/mm/dd.
1 parent da95f51 commit 11097fe

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Middleware/Language.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public function process(
7979
$lang = self::detectLocale($loris, $request);
8080
if ($lang !== null) {
8181
\setlocale(LC_MESSAGES, $lang . '.utf8');
82+
// Set the default_locale for intl to match the user preference,
83+
// so that date formatting works correctly.
84+
// PHPCS complains about ini_set not being allowed, but there
85+
// does not seem to be any other way to do this.
86+
//phpcs:ignore
87+
ini_set('intl.default_locale', $lang);
8288
return $this->next->process(
8389
$request->withAttribute("locale", $lang),
8490
$handler

0 commit comments

Comments
 (0)