107 lines
3.2 KiB
PHP
107 lines
3.2 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
// -----------------------------------------------------------
|
|
// Session starten
|
|
// -----------------------------------------------------------
|
|
if (php_sapi_name() !== 'cli') {
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
|
|
session_name('usbcheck_session');
|
|
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'domain' => '',
|
|
'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
|
|
'httponly' => true,
|
|
'samesite' => 'Lax',
|
|
]);
|
|
|
|
session_start();
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------
|
|
// 1) Sprache bestimmen (vor dem Laden der JSON-Dateien!)
|
|
// -----------------------------------------------------------
|
|
$lang = $_GET['lang'] ?? null;
|
|
$lang = strtolower($lang);
|
|
|
|
if (!preg_match('/^[a-z]{2}$/', $lang)) {
|
|
$lang = null;
|
|
}
|
|
|
|
// -----------------------------------------------------------
|
|
// 2) Verfügbare JSON-Sprachen erkennen
|
|
// -----------------------------------------------------------
|
|
$i18nDir = __DIR__ . '/../public/assets/i18n';
|
|
$langFiles = glob($i18nDir . '/*.json') ?: [];
|
|
|
|
$availableLangs = [];
|
|
|
|
foreach ($langFiles as $file) {
|
|
$json = json_decode(file_get_contents($file), true);
|
|
if (!$json || !isset($json['meta'])) continue;
|
|
|
|
$meta = $json['meta'];
|
|
$code = strtolower($meta['code'] ?? basename($file, ".json"));
|
|
|
|
$availableLangs[$code] = [
|
|
'code' => $code,
|
|
'label' => $meta['label'] ?? strtoupper($code),
|
|
'flag' => $meta['flag'] ?? '🏳️'
|
|
];
|
|
}
|
|
|
|
// Falls Sprache ungültig → erste verfügbare Sprache wählen
|
|
if (!$lang || !isset($availableLangs[$lang])) {
|
|
$lang = array_key_first($availableLangs) ?: 'en';
|
|
}
|
|
|
|
// -----------------------------------------------------------
|
|
// 3) Aktive Sprachdatei laden
|
|
// -----------------------------------------------------------
|
|
$activeLangFile = $i18nDir . '/' . $lang . '.json';
|
|
$activeLangData = [];
|
|
|
|
if (is_readable($activeLangFile)) {
|
|
$json = json_decode(file_get_contents($activeLangFile), true);
|
|
if (is_array($json)) {
|
|
$activeLangData = $json;
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------
|
|
// 4) Fallback-Sprache (EN)
|
|
// -----------------------------------------------------------
|
|
$fallbackLangData = [];
|
|
$fallbackFile = $i18nDir . '/en.json';
|
|
|
|
if ($lang !== 'en' && is_readable($fallbackFile)) {
|
|
$json = json_decode(file_get_contents($fallbackFile), true);
|
|
if (is_array($json)) {
|
|
$fallbackLangData = $json;
|
|
}
|
|
}
|
|
|
|
// -----------------------------------------------------------
|
|
// 5) Globale i18n-Struktur bereitstellen
|
|
// -----------------------------------------------------------
|
|
$GLOBALS['lang'] = $lang;
|
|
$GLOBALS['availableLangs'] = $availableLangs;
|
|
|
|
$GLOBALS['i18n'] = [
|
|
'current' => $activeLangData,
|
|
'fallback' => $fallbackLangData,
|
|
];
|
|
|
|
// -----------------------------------------------------------
|
|
// 6) Rest des Systems laden
|
|
// -----------------------------------------------------------
|
|
require_once __DIR__ . "/config.php";
|
|
require_once __DIR__ . "/db.php";
|
|
require_once __DIR__ . '/../src/functions.php';
|