import json from pathlib import Path from nicegui import ui from fastapi import Request from gui import gui_style # JSON laden - liegt laut Screenshot direkt in gui/ _JSON_PATH = Path(__file__).resolve().parent / 'imprint.json' with open(_JSON_PATH, encoding='utf-8') as f: imprint_data: dict = json.load(f) # ------------------------------------------------------- SECTION_TITLES_FALLBACK = { "howto": "Kurzanleitung", "rules": "Allgemeine Regeln", "imprint": "Impressum", "privacy": "Datenschutz", } def _get_locale(request: Request) -> str: default = imprint_data.get('default_locale', 'de') lang = request.query_params.get('lang', default) if lang not in imprint_data.get('locales', {}): lang = default return lang def _get_locale_options() -> list[str]: return list(imprint_data.get('locales', {}).keys()) def setup_routes(): @ui.page('/info', dark=True) def info_page(request: Request): gui_style.apply_design() lang = _get_locale(request) locale_data = imprint_data['locales'][lang] page_title = locale_data.get('page', {}).get('title', 'Info') sections = sorted(locale_data.get('sections', []), key=lambda s: s.get('order', 0)) with ui.row().classes("w-full items-center justify-between"): ui.button(text="Zurück", on_click=lambda: ui.navigate.to('/')) ui.label(page_title).classes("text-xl font-bold") ui.select( options=_get_locale_options(), value=lang, label='Sprache', on_change=lambda e: ui.navigate.to(f'/info?lang={e.value}'), ).classes("min-w-[8rem]") ui.separator().classes("my-4") with ui.column().classes("w-full gap-4"): for section in sections: title = section.get('title', SECTION_TITLES_FALLBACK.get(section.get('id', ''), '')) blocks = section.get('blocks', []) with ui.card().classes("w-full"): if title: ui.label(title).classes("text-lg font-semibold mb-2") for block in blocks: btype = block.get('type', 'markdown') if btype == 'markdown': raw = block.get('content', '') # Unterstützt sowohl String als auch Array if isinstance(raw, list): content = '\n'.join(raw) else: content = raw ui.markdown(content).classes("prose max-w-none") elif btype == 'divider': ui.separator().classes("my-2")