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.
|
* Nav-Anker für eine Seite aus der Sprachdatei holen.
|
||||||
*
|
*
|
||||||
* Erwartete Struktur im JSON:
|
* Unterstützte Varianten im JSON:
|
||||||
|
*
|
||||||
|
* Variante A (direkte Labels):
|
||||||
* "pages": {
|
* "pages": {
|
||||||
* "landing": {
|
* "landing": {
|
||||||
* "meta": { ... },
|
|
||||||
* "anchors": {
|
* "anchors": {
|
||||||
* "how": "So funktioniert USBCheck",
|
* "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:
|
* Rückgabe-Format:
|
||||||
* [
|
* [
|
||||||
* [ 'href' => '#how', 'label' => 'So funktioniert USBCheck' ],
|
* [ 'href' => '#how', 'label' => 'So funktioniert USBCheck', 'i18n' => '' ],
|
||||||
* [ 'href' => '#problem', 'label' => 'Warum gefälschte USB-Sticks gefährlich sind' ],
|
* [ 'href' => '#problem', 'label' => '', 'i18n' => 'nav_problem' ],
|
||||||
* ...
|
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
function app_get_nav_anchors(string $pageKey): array
|
function app_get_nav_anchors(string $pageKey): array
|
||||||
@@ -302,23 +321,54 @@ function app_get_nav_anchors(string $pageKey): array
|
|||||||
$lang = $GLOBALS['lang'] ?? 'en';
|
$lang = $GLOBALS['lang'] ?? 'en';
|
||||||
$data = app_i18n_load_lang_json($lang);
|
$data = app_i18n_load_lang_json($lang);
|
||||||
|
|
||||||
$nav = $data['pages'][$pageKey]['anchors'] ?? null;
|
$cfg = $data['pages'][$pageKey]['anchors'] ?? null;
|
||||||
if (!is_array($nav)) {
|
if (!is_array($cfg)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$anchors = [];
|
$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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$anchors[] = [
|
$anchors[] = [
|
||||||
'href' => '#' . $id,
|
'href' => $href,
|
||||||
'label' => $label,
|
'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">
|
<div class="flex items-center gap-6">
|
||||||
|
|
||||||
<!-- Hauptnavigation -->
|
<!-- Hauptnavigation -->
|
||||||
<?php if (!empty($navAnchors)): ?>
|
<!-- 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]">
|
<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 foreach ($navAnchors as $item): ?>
|
||||||
<a href="<?= htmlspecialchars($item['href'] ?? '#') ?>"
|
<?php
|
||||||
class="hover:text-brand-primary transition-colors">
|
$href = $item['href'] ?? '#';
|
||||||
<?= htmlspecialchars($item['label'] ?? '') ?>
|
$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>
|
</a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</nav>
|
</nav>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
<!-- Language Switcher -->
|
<!-- Language Switcher -->
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
|
|||||||
Reference in New Issue
Block a user