asd
This commit is contained in:
@@ -278,23 +278,42 @@ function app_i18n_load_lang_json(string $lang): array
|
||||
/**
|
||||
* Nav-Anker für eine Seite aus der Sprachdatei holen.
|
||||
*
|
||||
* Erwartete Struktur im JSON:
|
||||
* Unterstützte Varianten im JSON:
|
||||
*
|
||||
* Variante A (direkte Labels):
|
||||
* "pages": {
|
||||
* "landing": {
|
||||
* "meta": { ... },
|
||||
* "anchors": {
|
||||
* "how": "So funktioniert USBCheck",
|
||||
* "problem": "Warum gefälschte USB-Sticks gefährlich sind",
|
||||
* ...
|
||||
* "problem": "Warum gefälschte USB-Sticks gefährlich sind"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Variante B (i18n-Keys):
|
||||
* "pages": {
|
||||
* "landing": {
|
||||
* "anchors": {
|
||||
* "how": "nav_how",
|
||||
* "problem": "nav_problem"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Variante C (explizit):
|
||||
* "pages": {
|
||||
* "landing": {
|
||||
* "anchors": {
|
||||
* "how": { "label": "So funktioniert USBCheck", "i18n": "nav_how" },
|
||||
* "problem": { "i18n": "nav_problem" }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Rückgabe-Format:
|
||||
* [
|
||||
* [ 'href' => '#how', 'label' => 'So funktioniert USBCheck' ],
|
||||
* [ 'href' => '#problem', 'label' => 'Warum gefälschte USB-Sticks gefährlich sind' ],
|
||||
* ...
|
||||
* [ 'href' => '#how', 'label' => 'So funktioniert USBCheck', 'i18n' => '' ],
|
||||
* [ 'href' => '#problem', 'label' => '', 'i18n' => 'nav_problem' ],
|
||||
* ]
|
||||
*/
|
||||
function app_get_nav_anchors(string $pageKey): array
|
||||
@@ -302,23 +321,54 @@ 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)) {
|
||||
$cfg = $data['pages'][$pageKey]['anchors'] ?? null;
|
||||
if (!is_array($cfg)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$anchors = [];
|
||||
foreach ($nav as $id => $label) {
|
||||
$id = trim((string)$id);
|
||||
$label = trim((string)$label);
|
||||
|
||||
if ($id === '' || $label === '') {
|
||||
foreach ($cfg as $id => $value) {
|
||||
$id = trim((string)$id);
|
||||
if ($id === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$href = '#' . $id;
|
||||
$label = null;
|
||||
$i18n = null;
|
||||
|
||||
if (is_string($value)) {
|
||||
$valueTrim = trim($value);
|
||||
|
||||
if ($valueTrim !== '') {
|
||||
// Heuristik:
|
||||
// - enthält der Wert Leerzeichen → fertiges Label
|
||||
// - sonst → i18n-Key (z.B. "nav_how")
|
||||
if (preg_match('/\s/u', $valueTrim)) {
|
||||
$label = $valueTrim;
|
||||
} else {
|
||||
$i18n = $valueTrim;
|
||||
}
|
||||
}
|
||||
} elseif (is_array($value)) {
|
||||
if (!empty($value['label'])) {
|
||||
$label = (string)$value['label'];
|
||||
}
|
||||
if (!empty($value['i18n'])) {
|
||||
$i18n = (string)$value['i18n'];
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn weder Label noch i18n da ist → überspringen
|
||||
if ($label === null && $i18n === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$anchors[] = [
|
||||
'href' => '#' . $id,
|
||||
'label' => $label,
|
||||
'href' => $href,
|
||||
'label' => $label ?? '',
|
||||
'i18n' => $i18n ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -119,16 +119,27 @@ function build_lang_url(string $code, string $path, array $query): string
|
||||
<div class="flex items-center gap-6">
|
||||
|
||||
<!-- Hauptnavigation -->
|
||||
<?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; ?>
|
||||
<!-- Hauptnavigation -->
|
||||
<?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): ?>
|
||||
<?php
|
||||
$href = $item['href'] ?? '#';
|
||||
$label = $item['label'] ?? '';
|
||||
$i18nKey = $item['i18n'] ?? '';
|
||||
?>
|
||||
<a href="<?= htmlspecialchars($href) ?>"
|
||||
class="hover:text-brand-primary transition-colors"
|
||||
<?php if ($i18nKey !== ''): ?>
|
||||
data-i18n="<?= htmlspecialchars($i18nKey) ?>"
|
||||
<?php endif; ?>
|
||||
>
|
||||
<?= htmlspecialchars($label) ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<!-- Language Switcher -->
|
||||
<div class="relative">
|
||||
|
||||
Reference in New Issue
Block a user