Make sure the given locale is available for php-intl/ICU

Or fallback to default language

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-03-22 14:49:59 +01:00
parent 70830c514d
commit e96c2256ef
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -50,6 +50,10 @@ $date_format['txt_datetime_short'] = 'dd-MM-y HH:mm';
function formatDate(string $format, $date) {
global $locale;
$locales = ResourceBundle::getLocales('');
if (!in_array($locale, $locales, true)) {
$locale = DEFAULT_LANGUAGE;
}
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
if ($format !== '') {
$formatter->setPattern($format);