Tłumaczenia - poprawki.

This commit is contained in:
2026-09-25 18:16:53 +02:00
parent 4fde92d323
commit 80e1aa12ed
6 changed files with 178 additions and 49 deletions
+37 -5
View File
@@ -6,6 +6,21 @@ declare(strict_types=1);
* Wspólne funkcje cache/upstream menu (api/menu.php + scripts/refresh_menu_cache.php).
*/
if (!function_exists('array_is_list')) {
/** Polyfill PHP < 8.1 */
function array_is_list(array $array): bool
{
$i = 0;
foreach ($array as $k => $_) {
if ($k !== $i++) {
return false;
}
}
return true;
}
}
function menuCacheDir(): string
{
$dir = __DIR__ . '/cache';
@@ -16,6 +31,20 @@ function menuCacheDir(): string
return $dir;
}
function assertMenuCacheWritable(): void
{
$dir = menuCacheDir();
if (!is_dir($dir) || !is_writable($dir)) {
$user = function_exists('posix_geteuid')
? ((string) (@posix_getpwuid(posix_geteuid())['name'] ?? posix_geteuid()))
: get_current_user();
throw new RuntimeException(
"Katalog cache nie jest zapisywalny: {$dir} (proces jako: {$user}). "
. 'Na serwerze: chown -R www-data:www-data api/cache && chmod 775 api/cache'
);
}
}
function menuCachePath(string $lang): string
{
$safe = preg_replace('/[^a-z0-9_-]/i', '', strtolower($lang)) ?: 'pl';
@@ -46,11 +75,14 @@ function readMenuCache(string $cacheFile): ?array
function writeMenuCache(string $cacheFile, array $payload): void
{
file_put_contents(
$cacheFile,
json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
LOCK_EX
);
$json = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($json === false) {
throw new RuntimeException('Nie udało się zserializować cache: ' . $cacheFile);
}
$ok = @file_put_contents($cacheFile, $json, LOCK_EX);
if ($ok === false) {
throw new RuntimeException('Permission denied przy zapisie: ' . $cacheFile);
}
}
function fetchUpstreamMenu(string $url, int $timeout): ?array