fightbulc / moment.php

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Other
973 stars 154 forks source link

fetchSimilarLocales: All-lowercase Accept-Language header doesn't work #211

Open cachius opened 2 years ago

cachius commented 2 years ago

Safari on MacOS sends an all-lowercase header like Accept-Language: de-de. On case-sensitive filesystems this causes MomentLocale.php::fetchSimilarLocales not finding alternatives.

$dir = dirname($path);
$lang = basename($path);

$locales = glob("$dir".DIRECTORY_SEPARATOR.substr($lang,0,2) . '*.php');

works around that. It would be even better to be also case-insensitive to the first part of the locale. C.f. Can PHP's glob() be made to find files in a case insensitive manner?