= 3) { $fileLang = $parts[count($parts) - 2]; if ($fileLang === $lang && is_file("$dirPath/$file")) { return true; } } } return false; } function formatDate(string $dateString, string $lang): string { if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $dateString, $matches)) { return $dateString; } $translations = loadTranslations($lang); $day = (int)$matches[3]; $monthIndex = (int)$matches[2] - 1; $year = $matches[1]; if (isset($translations['months'])) { $months = array_map('trim', explode(',', $translations['months'])); $month = $months[$monthIndex] ?? $matches[2]; } else { $month = $matches[2]; } return "$day. $month $year"; }