feat: Website und Hub zweisprachig (Deutsch/Englisch)

Website (rinkplanner.programmschmiede.de) liegt jetzt im Repo unter web/:
Sprachweiche nach Accept-Language (der User-Agent enthält keine Sprache),
/de/ und /en/ als eigene URLs mit hreflang, Cookie für die manuelle Wahl,
Texte in web/i18n.php, Markup in web/template.php. Deployment über
tools/deploy_web.sh (--sync, --check, --all); /index.html leitet weiter.

Hub: optionale englische Oberfläche über den DE/EN-Umschalter, Cookie
RHUB_LANG, Route /language. Alle Texte (Views, Meldungen, Validierung,
API-messages) stehen in hub/app/i18n_strings.php und laufen über t();
Datum und Zahlen folgen der Sprache. Die API behält ihre code-Felder und
antwortet ohne Cookie weiter deutsch.

deploy_hub.sh --check prüft jetzt Schlüsselparität und fehlende t()-Schlüssel.
Doku: docs/website.md neu, docs/hub.md und AGENTS.md ergänzt.
This commit is contained in:
torsten 2026-11-12 22:38:32 +01:00
parent 6c8dc942e8
commit 9819311403
41 changed files with 2801 additions and 326 deletions

View file

@ -84,6 +84,9 @@ function url(string $path = '/'): string
return $base . $path;
}
/** Cache-Buster für /assets/: bei Änderungen an hub.css erhöhen. */
const HUB_ASSET_VERSION = '3';
function redirect(string $path, int $status = 303): never
{
header('Location: ' . url($path), true, $status);
@ -141,17 +144,27 @@ function fmt_dt(?string $utc): string
}
try {
$date = new DateTimeImmutable($utc, new DateTimeZone('UTC'));
return $date->setTimezone(new DateTimeZone('Europe/Berlin'))->format('d.m.Y H:i');
$format = hub_locale() === 'en' ? 'Y-m-d H:i' : 'd.m.Y H:i';
return $date->setTimezone(new DateTimeZone('Europe/Berlin'))->format($format);
} catch (Throwable) {
return '–';
}
}
/** Zahl mit den Trennzeichen der aktuellen Sprache. */
function fmt_number(float $value, int $decimals = 1): string
{
if (hub_locale() === 'en') {
return number_format($value, $decimals, '.', ',');
}
return number_format($value, $decimals, ',', '.');
}
function human_bytes(int|float|null $bytes): string
{
$bytes = (float) ($bytes ?? 0);
if ($bytes < 1024) {
return number_format($bytes, 0, ',', '.') . ' B';
return fmt_number($bytes, 0) . ' B';
}
$units = ['KB', 'MB', 'GB'];
$index = -1;
@ -159,7 +172,7 @@ function human_bytes(int|float|null $bytes): string
$bytes /= 1024;
$index++;
} while ($bytes >= 1024 && $index < count($units) - 1);
return number_format($bytes, 1, ',', '.') . ' ' . $units[$index];
return fmt_number($bytes, 1) . ' ' . $units[$index];
}
function truncate_text(string $value, int $length): string
@ -229,7 +242,7 @@ function csrf_valid(): bool
function csrf_require(): void
{
if (!csrf_valid()) {
abort_page(419, 'Die Sitzung ist abgelaufen. Bitte die Seite neu laden.');
abort_page(419, t('auth.session_expired'));
}
}
@ -272,11 +285,11 @@ function render(string $view, array $data = []): string
return (string) ob_get_clean();
}
function render_page(string $view, array $data = [], string $title = 'Kür-Hub'): void
function render_page(string $view, array $data = [], ?string $title = null): void
{
$content = render($view, $data);
echo render('layout', [
'title' => $title,
'title' => $title ?? t('page.title_default'),
'content' => $content,
'user' => auth_user(),
]);
@ -287,7 +300,7 @@ function abort_page(int $status, string $message): never
http_response_code($status);
$content = render('error', ['status' => $status, 'message' => $message]);
echo render('layout', [
'title' => 'Fehler ' . $status,
'title' => t('page.title_error', ['status' => $status]),
'content' => $content,
'user' => auth_user(),
]);
@ -303,13 +316,13 @@ function password_policy_error(string $password, string $username = ''): ?string
{
$length = mb_strlen($password, 'UTF-8');
if ($length < 10) {
return 'Das Passwort muss mindestens 10 Zeichen lang sein.';
return t('password.min');
}
if ($length > 200) {
return 'Das Passwort darf höchstens 200 Zeichen lang sein.';
return t('password.max');
}
if ($username !== '' && mb_strtolower($password) === mb_strtolower($username)) {
return 'Das Passwort darf nicht dem Benutzernamen entsprechen.';
return t('password.same_as_username');
}
return null;
}