This commit is contained in:
2025-11-28 03:31:46 +01:00
parent 5de109b649
commit cf68494f55
7 changed files with 132 additions and 12 deletions

View File

@@ -232,3 +232,95 @@ function app_i18n_get_frontend_config(): array
'available' => $GLOBALS['availableLangs'] ?? [],
];
}
/**
* Komplette JSON-Struktur für eine Sprache laden.
* Nutzt einfachen Request-Cache, damit pro Sprache nur einmal von Platte gelesen wird.
*/
function app_i18n_load_lang_json(string $lang): array
{
static $cache = [];
$lang = strtolower(substr($lang, 0, 5));
if (isset($cache[$lang])) {
return $cache[$lang];
}
$baseDir = realpath(__DIR__ . '/../public/assets/i18n');
if ($baseDir === false) {
$cache[$lang] = [];
return $cache[$lang];
}
$path = $baseDir . '/' . $lang . '.json';
if (!is_file($path)) {
// Fallback: en.json, falls vorhanden
$fallback = $baseDir . '/en.json';
if (is_file($fallback)) {
$json = @file_get_contents($fallback);
$data = json_decode($json, true);
$cache[$lang] = is_array($data) ? $data : [];
return $cache[$lang];
}
$cache[$lang] = [];
return $cache[$lang];
}
$json = @file_get_contents($path);
$data = json_decode($json, true);
$cache[$lang] = is_array($data) ? $data : [];
return $cache[$lang];
}
/**
* Nav-Anker für eine Seite aus der Sprachdatei holen.
*
* Erwartete Struktur im JSON:
* "pages": {
* "landing": {
* "meta": { ... },
* "anchors": {
* "how": "So funktioniert USBCheck",
* "problem": "Warum gefälschte USB-Sticks gefährlich sind",
* ...
* }
* }
* }
*
* Rückgabe-Format:
* [
* [ 'href' => '#how', 'label' => 'So funktioniert USBCheck' ],
* [ 'href' => '#problem', 'label' => 'Warum gefälschte USB-Sticks gefährlich sind' ],
* ...
* ]
*/
function app_get_nav_anchors(string $pageKey): array
{
$lang = $GLOBALS['lang'] ?? 'en';
$data = app_i18n_load_lang_json($lang);
$nav = $data['pages'][$pageKey]['anchors'] ?? null;
if (!is_array($nav)) {
return [];
}
$anchors = [];
foreach ($nav as $id => $label) {
$id = trim((string)$id);
$label = trim((string)$label);
if ($id === '' || $label === '') {
continue;
}
$anchors[] = [
'href' => '#' . $id,
'label' => $label,
];
}
return $anchors;
}

View File

@@ -6,9 +6,16 @@ $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https'
$host = $_SERVER['HTTP_HOST'] ?? app_primary_domain();
$baseUrl = $scheme . '://' . $host;
// Wenn $navAnchors NICHT gesetzt ist → leeres Array
// Aktueller Page-Key (z.B. 'landing', 'fakecheck', 'dashboard')
$pageKey = $GLOBALS['pageKey'] ?? null;
// Nav-Anker: wenn nicht explizit gesetzt, aus der i18n-JSON holen
if (!isset($navAnchors) || !is_array($navAnchors)) {
$navAnchors = [];
if ($pageKey && function_exists('app_get_nav_anchors')) {
$navAnchors = app_get_nav_anchors($pageKey); // ['href' => '#how', 'label' => '...']
} else {
$navAnchors = [];
}
}
// Session sollte in config/fileload.php bereits gestartet sein.
@@ -112,14 +119,16 @@ function build_lang_url(string $code, string $path, array $query): string
<div class="flex items-center gap-6">
<!-- Hauptnavigation -->
<nav class="flex flex-wrap items-center gap-4 sm:gap-6 text-xs font-medium text-brand-muted uppercase tracking-[0.18em]">
<?php foreach ($navAnchors as $item): ?>
<a href="<?= htmlspecialchars($item['href']) ?>"
class="hover:text-brand-primary transition-colors"
data-i18n="<?= htmlspecialchars($item['key']) ?>">
</a>
<?php endforeach; ?>
</nav>
<?php if (!empty($navAnchors)): ?>
<nav class="flex flex-wrap items-center gap-4 sm:gap-6 text-xs font-medium text-brand-muted uppercase tracking-[0.18em]">
<?php foreach ($navAnchors as $item): ?>
<a href="<?= htmlspecialchars($item['href'] ?? '#') ?>"
class="hover:text-brand-primary transition-colors">
<?= htmlspecialchars($item['label'] ?? '') ?>
</a>
<?php endforeach; ?>
</nav>
<?php endif; ?>
<!-- Language Switcher -->
<div class="relative">

View File

@@ -9,9 +9,25 @@
"landing": {
"meta": {
"title": "KEIN TITEL"
}
},
,
"anchors": {
"how": "So funktioniert USBCheck",
"problem": "Warum gefälschte USB-Sticks gefährlich sind",
"features": "Funktionen",
"security": "Sicherheit",
"faq": "FAQ"
}
},
"main": {
,
"anchors": {
"how": "So funktioniert USBCheck",
"problem": "Warum gefälschte USB-Sticks gefährlich sind",
"features": "Funktionen",
"security": "Sicherheit",
"faq": "FAQ"
},
"sections": {
"security": {
"security_kicker": "Sicherheit &amp; Datenschutz",

View File

@@ -1,5 +1,6 @@
<?php
$pageKey = 'landing';
$GLOBALS['pageKey'] = $pageKey;
require_once dirname(__DIR__) . '/config/fileload.php';

View File

@@ -1,6 +1,7 @@
<?php
// public/dashboard/index.php
$pageKey = 'dashboard';
$GLOBALS['pageKey'] = $pageKey;
require_once $_SERVER['DOCUMENT_ROOT']. '/../config/fileload.php';

View File

@@ -1,6 +1,6 @@
<?php
$pageKey = 'fakecheck';
$GLOBALS['pageKey'] = $pageKey;
/*
* USBCheck Fake USB Check - Landingpage
* --------------------------------------*/

View File

@@ -1,5 +1,6 @@
<?php
$pageKey = 'login';
$GLOBALS['pageKey'] = $pageKey;
require_once $_SERVER['DOCUMENT_ROOT']. '/../config/fileload.php';
tpl_add_script('/assets/js/auth.js', 'footer', true, false, '', 'auth-1');