mivita/app/Services/LocaleGuard.php
2026-04-10 17:15:27 +02:00

30 lines
656 B
PHP

<?php
namespace App\Services;
class LocaleGuard
{
/**
* @return array<int, string>
*/
public static function supportedLocaleCodes(): array
{
return array_keys(config('localization.supportedLocales'));
}
public static function isSupported(string $locale): bool
{
return in_array(strtolower($locale), self::supportedLocaleCodes(), true);
}
public static function normalize(?string $locale): ?string
{
if ($locale === null || $locale === '') {
return null;
}
$lower = strtolower($locale);
return self::isSupported($lower) ? $lower : null;
}
}