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

@ -12,7 +12,7 @@ function page_handle(string $method, string $path): void
{
$path = '/' . trim($path, '/');
if (!in_array($method, ['GET', 'POST'], true)) {
abort_page(405, 'Diese Methode ist nicht erlaubt.');
abort_page(405, t('page.method_not_allowed'));
}
if ($path === '/health') {
@ -20,11 +20,20 @@ function page_handle(string $method, string $path): void
return;
}
// Sprachwahl über den DE/EN-Umschalter; muss auch ohne Anmeldung gehen.
if ($path === '/language') {
$lang = strtolower(substr(query_string('lang'), 0, 2));
if (in_array($lang, HUB_LOCALES, true)) {
hub_locale_set($lang);
}
redirect(auth_next_url('/'));
}
$user = auth_user();
if ($user !== null && $user['must_change_password'] === 1
&& !in_array($path, ['/account', '/account/password', '/logout'], true)
&& !in_array($path, ['/account', '/account/password', '/logout', '/language'], true)
) {
flash('info', 'Bitte zuerst das Passwort ändern.');
flash('info', t('auth.change_password_first'));
redirect('/account');
}
@ -41,7 +50,7 @@ function page_handle(string $method, string $path): void
redirect('/');
}
auth_logout();
flash('success', 'Abgemeldet.');
flash('success', t('auth.logged_out'));
redirect('/login');
}
if ($path === '/') {
@ -94,7 +103,7 @@ function page_handle(string $method, string $path): void
}
if ($path === '/admin/audit') {
require_admin_page();
render_page('admin_audit', ['entries' => audit_list(200)], 'Audit-Log');
render_page('admin_audit', ['entries' => audit_list(200)], t('page.admin_audit'));
return;
}
@ -115,7 +124,7 @@ function page_handle(string $method, string $path): void
return;
}
abort_page(404, 'Diese Seite gibt es nicht.');
abort_page(404, t('page.not_found'));
}
function health_check(): void
@ -163,19 +172,19 @@ function page_login(string $method): void
'error' => $error,
'login' => $login,
'next' => $next,
], 'Anmelden');
], t('page.login'));
}
function username_error(string $username): ?string
{
if (mb_strlen($username, 'UTF-8') < 3 || mb_strlen($username, 'UTF-8') > 32) {
return 'Der Benutzername muss 3 bis 32 Zeichen lang sein.';
return t('username.length');
}
if (preg_match('/^[a-z0-9](?:[a-z0-9._-]{1,30}[a-z0-9])$/u', $username) !== 1) {
return 'Nur Kleinbuchstaben, Ziffern, Punkt, Bindestrich und Unterstrich; Anfang und Ende alphanumerisch.';
return t('username.charset');
}
if (in_array($username, HUB_RESERVED_USERNAMES, true)) {
return 'Dieser Benutzername ist reserviert.';
return t('username.reserved');
}
return null;
}
@ -209,7 +218,7 @@ function page_register(string $method): void
$input['email'] = post_string('email');
if ($invite === null) {
$errors[] = 'Dieser Einladungscode ist ungültig, abgelaufen oder bereits eingelöst.';
$errors[] = t('register.invalid_invite');
} elseif (!empty($invite['email']) && $input['email'] === '') {
$input['email'] = (string) $invite['email'];
}
@ -221,15 +230,15 @@ function page_register(string $method): void
$input['display_name'] = $input['username'];
}
if (mb_strlen($input['display_name'], 'UTF-8') > 64) {
$errors[] = 'Der Anzeigename darf höchstens 64 Zeichen lang sein.';
$errors[] = t('register.display_name_long');
}
if ($input['email'] !== '' && filter_var($input['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Die E-Mail-Adresse ist nicht gültig.';
$errors[] = t('register.email_invalid');
}
if ($invite !== null && !empty($invite['email'])
&& strcasecmp((string) $invite['email'], $input['email']) !== 0
) {
$errors[] = 'Diese Einladung ist an eine andere E-Mail-Adresse gebunden.';
$errors[] = t('register.email_mismatch');
}
$password = (string) ($_POST['password'] ?? '');
$repeat = (string) ($_POST['password_repeat'] ?? '');
@ -238,10 +247,10 @@ function page_register(string $method): void
$errors[] = $policy;
}
if ($password !== $repeat) {
$errors[] = 'Die Passwortwiederholung passt nicht.';
$errors[] = t('register.password_mismatch');
}
if (($_POST['rights'] ?? '') !== '1') {
$errors[] = 'Bitte die Beta-Regeln akzeptieren.';
$errors[] = t('register.rights_required');
}
if (!$errors && $invite !== null) {
@ -268,7 +277,7 @@ function page_register(string $method): void
$newId = (int) $pdo->lastInsertId();
if (!invite_consume((int) $invite['id'], $newId)) {
$pdo->rollBack();
$errors[] = 'Der Einladungscode wurde gerade eingelöst. Bitte einen neuen Code anfordern.';
$errors[] = t('register.invite_taken');
} else {
audit('invite.use', 'invite', (int) $invite['id'], $input['username'], $newId);
audit('user.register', 'user', $newId, $input['username'], $newId);
@ -279,9 +288,9 @@ function page_register(string $method): void
$pdo->rollBack();
}
if (str_contains($exception->getMessage(), 'uq_users_username')) {
$errors[] = 'Dieser Benutzername ist schon vergeben.';
$errors[] = t('register.username_taken');
} elseif (str_contains($exception->getMessage(), 'uq_users_email')) {
$errors[] = 'Diese E-Mail-Adresse ist schon registriert.';
$errors[] = t('register.email_taken');
} else {
throw $exception;
}
@ -291,7 +300,7 @@ function page_register(string $method): void
$user = auth_user_by_id($newId);
if ($user !== null) {
auth_login($user);
flash('success', 'Willkommen im Kür-Hub!');
flash('success', t('auth.welcome'));
redirect('/');
}
}
@ -303,7 +312,7 @@ function page_register(string $method): void
'code' => $code,
'errors' => $errors,
'input' => $input,
], 'Registrieren');
], t('page.register'));
}
function page_dashboard(string $method): void
@ -320,7 +329,7 @@ function page_dashboard(string $method): void
'pages' => $result['pages'],
'query' => $query,
'mine' => $mine,
], 'Küren');
], t('page.dashboard'));
}
function page_routine_detail(int $id, string $method): void
@ -328,10 +337,10 @@ function page_routine_detail(int $id, string $method): void
$user = auth_require_login();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_view($routine, $user)) {
abort_page(403, 'Diese Kür ist nicht freigegeben.');
abort_page(403, t('routine.forbidden'));
}
render_page('routine', [
'routine' => $routine,
@ -345,10 +354,10 @@ function page_routine_file(int $id, string $kind): void
$user = auth_require_login();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_view($routine, $user)) {
abort_page(403, 'Diese Kür ist nicht freigegeben.');
abort_page(403, t('routine.forbidden'));
}
routine_send_file($routine, $kind);
}
@ -366,10 +375,10 @@ function page_upload(string $method): void
if ($method === 'POST') {
csrf_require();
if (!routine_upload_quota_ok((int) $user['id'])) {
$errors[] = 'Stündliches Upload-Limit erreicht. Bitte später erneut versuchen.';
$errors[] = t('upload.quota');
}
if (($_POST['rights'] ?? '') !== '1') {
$errors[] = 'Bitte bestätigen, dass du Kür und Musik teilen darfst.';
$errors[] = t('upload.rights_confirm');
}
if (!$errors) {
$package = routine_validate_package($_POST);
@ -378,16 +387,16 @@ function page_upload(string $method): void
} else {
$duplicate = routine_duplicate_exists((int) $user['id'], $package);
if ($duplicate !== null) {
flash('info', 'Diese Kür ist bereits im Hub.');
flash('info', t('upload.duplicate'));
redirect('/routines/' . $duplicate);
}
try {
$routineId = routine_create((int) $user['id'], $package);
flash('success', 'Kür veröffentlicht.');
flash('success', t('upload.published'));
redirect('/routines/' . $routineId);
} catch (Throwable $error) {
hub_log('Upload fehlgeschlagen: ' . $error->getMessage());
$errors[] = 'Die Kür konnte nicht gespeichert werden.';
$errors[] = t('upload.save_failed');
}
}
}
@ -400,7 +409,7 @@ function page_upload(string $method): void
'errors' => $errors,
'input' => $input,
'routine' => null,
], 'Kür hochladen');
], t('page.upload'));
}
function page_routine_revise(int $id, string $method): void
@ -408,10 +417,10 @@ function page_routine_revise(int $id, string $method): void
$user = auth_require_login();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_edit($routine, $user)) {
abort_page(403, 'Nur der Eigentümer oder ein Admin kann diese Kür ändern.');
abort_page(403, t('routine.edit_forbidden'));
}
$errors = [];
$input = [
@ -423,10 +432,10 @@ function page_routine_revise(int $id, string $method): void
if ($method === 'POST') {
csrf_require();
if (!routine_upload_quota_ok((int) $user['id'])) {
$errors[] = 'Stündliches Upload-Limit erreicht. Bitte später erneut versuchen.';
$errors[] = t('upload.quota');
}
if (($_POST['rights'] ?? '') !== '1') {
$errors[] = 'Bitte bestätigen, dass du Kür und Musik teilen darfst.';
$errors[] = t('upload.rights_confirm');
}
if (!$errors) {
$package = routine_validate_package($_POST);
@ -435,11 +444,11 @@ function page_routine_revise(int $id, string $method): void
} else {
try {
$revision = routine_add_revision($id, (int) $user['id'], $package);
flash('success', 'Neue Revision ' . $revision . ' gespeichert.');
flash('success', t('revision.saved', ['revision' => $revision]));
redirect('/routines/' . $id);
} catch (Throwable $error) {
hub_log('Revision fehlgeschlagen: ' . $error->getMessage());
$errors[] = 'Die Revision konnte nicht gespeichert werden.';
$errors[] = t('revision.save_failed');
}
}
}
@ -452,7 +461,7 @@ function page_routine_revise(int $id, string $method): void
'errors' => $errors,
'input' => $input,
'routine' => $routine,
], 'Neue Revision');
], t('page.revision'));
}
function page_routine_status(int $id, string $action, string $method): void
@ -464,14 +473,14 @@ function page_routine_status(int $id, string $action, string $method): void
csrf_require();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_edit($routine, $user)) {
abort_page(403, 'Nur der Eigentümer oder ein Admin kann diese Kür ändern.');
abort_page(403, t('routine.edit_forbidden'));
}
$status = $action === 'publish' ? 'published' : 'hidden';
routine_set_status($id, $status);
flash('success', $status === 'published' ? 'Kür ist wieder sichtbar.' : 'Kür wurde aus dem Hub genommen.');
flash('success', $status === 'published' ? t('routine.published_again') : t('routine.hidden_now'));
redirect('/routines/' . $id);
}
@ -480,7 +489,7 @@ function page_account(string $method): void
$user = auth_require_login();
render_page('account', [
'tokens' => tokens_list((int) $user['id']),
], 'Konto');
], t('page.account'));
}
function page_account_password(string $method): void
@ -496,14 +505,14 @@ function page_account_password(string $method): void
$errors = [];
if (!password_verify($current, (string) $user['password_hash'])) {
$errors[] = 'Das aktuelle Passwort ist falsch.';
$errors[] = t('account.current_wrong');
}
$policy = password_policy_error($password, (string) $user['username']);
if ($policy !== null) {
$errors[] = $policy;
}
if ($password !== $repeat) {
$errors[] = 'Die Passwortwiederholung passt nicht.';
$errors[] = t('register.password_mismatch');
}
if ($errors) {
foreach ($errors as $error) {
@ -517,7 +526,7 @@ function page_account_password(string $method): void
)->execute([hash_password($password), utc_now(), (int) $user['id']]);
auth_revoke_sessions((int) $user['id']);
audit('user.password_change', 'user', (int) $user['id']);
flash('success', 'Passwort geändert. Andere Sitzungen wurden abgemeldet.');
flash('success', t('account.password_changed'));
redirect('/account');
}
@ -533,7 +542,7 @@ function page_account_token_create(string $method): void
$name = 'App';
}
$created = token_create((int) $user['id'], $name);
flash_secret('Neuer API-Token – jetzt kopieren, er wird nicht erneut angezeigt', $created['token']);
flash_secret(t('token.created'), $created['token']);
redirect('/account');
}
@ -547,9 +556,9 @@ function page_account_token_revoke(string $method): void
$tokenId = (int) post_string('token_id');
if (token_revoke($tokenId, (int) $user['id'])) {
audit('token.revoke', 'token', $tokenId);
flash('success', 'Token widerrufen.');
flash('success', t('token.revoked'));
} else {
flash('error', 'Token nicht gefunden.');
flash('error', t('token.not_found'));
}
redirect('/account');
}
@ -564,7 +573,7 @@ function page_admin_invites(string $method): void
$days = (int) post_string('expires_days', '30');
$errors = [];
if ($email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Die E-Mail-Adresse ist nicht gültig.';
$errors[] = t('register.email_invalid');
}
if ($errors) {
foreach ($errors as $error) {
@ -574,14 +583,14 @@ function page_admin_invites(string $method): void
$code = invite_create($note, $email, $days, (int) $admin['id']);
$publicUrl = rtrim((string) config('app.public_url', ''), '/');
$link = $publicUrl . '/register?code=' . rawurlencode($code);
flash_secret('Einladungscode', $code . ' – Link: ' . $link);
flash('success', 'Einladung erstellt.');
flash_secret(t('invite.created_label'), $code . ' – Link: ' . $link);
flash('success', t('invite.created'));
}
redirect('/admin/invites');
}
render_page('admin_invites', [
'invites' => invites_list(),
], 'Einladungen');
], t('page.admin_invites'));
}
function page_admin_invite_revoke(string $method): void
@ -594,9 +603,9 @@ function page_admin_invite_revoke(string $method): void
$inviteId = (int) post_string('invite_id');
if (invite_revoke($inviteId)) {
audit('invite.revoke', 'invite', $inviteId);
flash('success', 'Einladung widerrufen.');
flash('success', t('invite.revoked'));
} else {
flash('error', 'Einladung konnte nicht widerrufen werden.');
flash('error', t('invite.revoke_failed'));
}
redirect('/admin/invites');
}
@ -608,7 +617,7 @@ function page_admin_users(string $method): void
'SELECT u.*, (SELECT COUNT(*) FROM routines r WHERE r.owner_id = u.id) AS routine_count
FROM users u ORDER BY u.created_at DESC, u.id DESC'
)->fetchAll();
render_page('admin_users', ['users' => $users], 'Benutzer');
render_page('admin_users', ['users' => $users], t('page.admin_users'));
}
function page_admin_user_action(string $method): void
@ -622,11 +631,11 @@ function page_admin_user_action(string $method): void
$action = post_string('action');
$target = auth_user_by_id($targetId);
if ($target === null) {
flash('error', 'Benutzer nicht gefunden.');
flash('error', t('user.not_found'));
redirect('/admin/users');
}
if ($targetId === (int) $admin['id']) {
flash('error', 'Das eigene Konto lässt sich hier nicht ändern.');
flash('error', t('user.self_change'));
redirect('/admin/users');
}
@ -634,11 +643,11 @@ function page_admin_user_action(string $method): void
db()->prepare("UPDATE users SET status = 'disabled' WHERE id = ?")->execute([$targetId]);
auth_revoke_sessions($targetId);
audit('user.disable', 'user', $targetId, (string) $target['username']);
flash('success', 'Benutzer deaktiviert.');
flash('success', t('user.disabled'));
} elseif ($action === 'enable') {
db()->prepare("UPDATE users SET status = 'active' WHERE id = ?")->execute([$targetId]);
audit('user.enable', 'user', $targetId, (string) $target['username']);
flash('success', 'Benutzer aktiviert.');
flash('success', t('user.enabled'));
} elseif ($action === 'reset') {
$alphabet = HUB_INVITE_ALPHABET;
$temp = '';
@ -650,11 +659,11 @@ function page_admin_user_action(string $method): void
)->execute([hash_password($temp), utc_now(), $targetId]);
auth_revoke_sessions($targetId);
audit('user.password_reset', 'user', $targetId, (string) $target['username']);
flash_secret('Temporäres Passwort für ' . $target['username'], $temp);
flash('info', 'Der Benutzer muss das Passwort bei der nächsten Anmeldung ändern.');
flash_secret(t('user.temp_password', ['user' => $target['username']]), $temp);
flash('info', t('user.must_change'));
} elseif ($action === 'delete') {
if (($_POST['confirm'] ?? '') !== '1') {
flash('error', 'Löschen muss bestätigt werden.');
flash('error', t('user.delete_confirm_required'));
redirect('/admin/users');
}
$stmt = db()->prepare('SELECT id FROM routines WHERE owner_id = ?');
@ -666,9 +675,9 @@ function page_admin_user_action(string $method): void
->execute([utc_now(), $targetId]);
audit('user.delete', 'user', $targetId, (string) $target['username']);
db()->prepare('DELETE FROM users WHERE id = ?')->execute([$targetId]);
flash('success', 'Benutzer und zugehörige Küren gelöscht.');
flash('success', t('user.deleted'));
} else {
flash('error', 'Unbekannte Aktion.');
flash('error', t('action.unknown'));
}
redirect('/admin/users');
}
@ -685,7 +694,7 @@ function page_admin_routines(string $method): void
'page' => $result['page'],
'pages' => $result['pages'],
'query' => $query,
], 'Alle Küren');
], t('page.admin_routines'));
}
function page_admin_routine_action(string $method): void
@ -699,21 +708,21 @@ function page_admin_routine_action(string $method): void
$action = post_string('action');
$routine = routine_fetch($routineId);
if ($routine === null) {
flash('error', 'Kür nicht gefunden.');
flash('error', t('routine.not_found_short'));
redirect('/admin/routines');
}
if ($action === 'hide' || $action === 'publish') {
routine_set_status($routineId, $action === 'publish' ? 'published' : 'hidden');
flash('success', 'Status geändert.');
flash('success', t('admin.status_changed'));
} elseif ($action === 'delete') {
if (($_POST['confirm'] ?? '') !== '1') {
flash('error', 'Löschen muss bestätigt werden.');
flash('error', t('user.delete_confirm_required'));
redirect('/admin/routines');
}
routine_delete($routineId);
flash('success', 'Kür endgültig gelöscht.');
flash('success', t('routine.deleted'));
} else {
flash('error', 'Unbekannte Aktion.');
flash('error', t('action.unknown'));
}
redirect('/admin/routines');
}