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

@ -47,11 +47,11 @@ function routine_music_name_valid(string $name): bool
function upload_error_message(int $code): string
{
return match ($code) {
UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => 'Die Datei ist zu groß.',
UPLOAD_ERR_PARTIAL => 'Der Upload wurde unterbrochen.',
UPLOAD_ERR_NO_FILE => 'Es wurde keine Datei ausgewählt.',
UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION => 'Die Datei konnte nicht gespeichert werden.',
default => 'Unbekannter Upload-Fehler.',
UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => t('upload.file_too_large'),
UPLOAD_ERR_PARTIAL => t('upload.interrupted'),
UPLOAD_ERR_NO_FILE => t('upload.no_file_chosen'),
UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION => t('upload.store_failed'),
default => t('upload.unknown_error'),
};
}
@ -112,20 +112,20 @@ function routine_validate_package(array $post): array
$routineFile = $_FILES['routine'] ?? null;
if (!is_array($routineFile) || ($routineFile['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
$errors[] = 'Bitte eine Kür-Datei (.json) auswählen.';
$errors[] = t('upload.select_routine');
return ['ok' => false, 'errors' => $errors];
}
$routineTmp = (string) $routineFile['tmp_name'];
$routineBytes = (int) $routineFile['size'];
if (!is_uploaded_file($routineTmp)) {
return ['ok' => false, 'errors' => ['Ungültiger Upload.']];
return ['ok' => false, 'errors' => [t('upload.invalid')]];
}
if ($routineBytes <= 0 || $routineBytes > $maxRoutine) {
$errors[] = 'Die Kür-Datei ist zu groß (max. ' . human_bytes($maxRoutine) . ').';
$errors[] = t('upload.routine_too_large', ['max' => human_bytes($maxRoutine)]);
}
$routineName = clean_filename((string) ($routineFile['name'] ?? 'kuer.json'));
if (!str_ends_with(strtolower($routineName), '.json')) {
$errors[] = 'Kürdateien müssen im JSON-Format vorliegen (.json).';
$errors[] = t('upload.routine_not_json');
}
if ($errors) {
return ['ok' => false, 'errors' => $errors];
@ -133,28 +133,28 @@ function routine_validate_package(array $post): array
$contents = file_get_contents($routineTmp);
if (!is_string($contents)) {
return ['ok' => false, 'errors' => ['Die Kür-Datei konnte nicht gelesen werden.']];
return ['ok' => false, 'errors' => [t('upload.read_failed')]];
}
try {
$json = json_decode($contents, true, 64, JSON_THROW_ON_ERROR);
} catch (JsonException) {
return ['ok' => false, 'errors' => ['Die Kür-Datei ist kein gültiges JSON.']];
return ['ok' => false, 'errors' => [t('upload.invalid_json')]];
}
if (!is_array($json)) {
return ['ok' => false, 'errors' => ['Die Kür-Datei enthält kein JSON-Objekt.']];
return ['ok' => false, 'errors' => [t('upload.no_json_object')]];
}
if (($json['format'] ?? '') !== 'rinkplanner.routine') {
return ['ok' => false, 'errors' => ['Das ist keine Rinkplanner-Kür (format fehlt oder ist falsch).']];
return ['ok' => false, 'errors' => [t('upload.not_rinkplanner')]];
}
$formatVersion = (int) ($json['format_version'] ?? 0);
if ($formatVersion !== 1) {
return ['ok' => false, 'errors' => ['Diese Kür-Formatversion wird nicht unterstützt.']];
return ['ok' => false, 'errors' => [t('upload.unsupported_version')]];
}
if (!is_array($json['sections'] ?? null)) {
return ['ok' => false, 'errors' => ['Die Kür enthält keine Abschnittsliste.']];
return ['ok' => false, 'errors' => [t('upload.no_sections')]];
}
if (count($json['sections']) > 500) {
return ['ok' => false, 'errors' => ['Die Kür hat zu viele Abschnitte (max. 500).']];
return ['ok' => false, 'errors' => [t('upload.too_many_sections')]];
}
$title = trim((string) ($json['title'] ?? ''));
@ -162,14 +162,14 @@ function routine_validate_package(array $post): array
$title = (string) pathinfo($routineName, PATHINFO_FILENAME);
}
if ($title === '') {
return ['ok' => false, 'errors' => ['Die Kür braucht einen Titel.']];
return ['ok' => false, 'errors' => [t('upload.title_required')]];
}
$title = truncate_text($title, 190);
$skater = truncate_text(trim((string) ($json['skater_name'] ?? '')), 190);
$category = truncate_text(trim((string) ($json['adult_category'] ?? '')), 40);
$musicFile = trim((string) ($json['music_file'] ?? ''));
if ($musicFile !== '' && !routine_music_name_valid($musicFile)) {
return ['ok' => false, 'errors' => ['Die Kür verweist auf einen ungültigen Musikdateinamen.']];
return ['ok' => false, 'errors' => [t('upload.bad_music_name')]];
}
$fileRoutineId = trim((string) ($json['routine_id'] ?? ''));
@ -177,10 +177,10 @@ function routine_validate_package(array $post): array
$audioFile = $_FILES['audio'] ?? null;
$hasAudioUpload = is_array($audioFile) && ($audioFile['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_NO_FILE;
if ($musicFile !== '' && !$hasAudioUpload) {
$errors[] = 'Die Kür verweist auf „' . $musicFile . '“. Bitte die passende Audiodatei mit hochladen.';
$errors[] = t('upload.music_missing', ['name' => $musicFile]);
}
if ($musicFile === '' && $hasAudioUpload) {
$errors[] = 'Die Kür verweist auf keine Musikdatei; die Audiodatei passt nicht dazu.';
$errors[] = t('upload.music_unexpected');
}
if ($hasAudioUpload) {
if (($audioFile['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
@ -190,15 +190,15 @@ function routine_validate_package(array $post): array
$audioBytes = (int) $audioFile['size'];
$audioName = clean_filename((string) ($audioFile['name'] ?? ''));
if (!is_uploaded_file($audioTmp)) {
$errors[] = 'Ungültiger Audio-Upload.';
$errors[] = t('upload.audio_invalid');
} elseif ($audioBytes <= 0 || $audioBytes > $maxAudio) {
$errors[] = 'Die Audiodatei ist zu groß (max. ' . human_bytes($maxAudio) . ').';
$errors[] = t('upload.audio_too_large', ['max' => human_bytes($maxAudio)]);
} elseif ($audioName !== $musicFile) {
$errors[] = 'Die Audiodatei heißt „' . $audioName . '“, die Kür verweist aber auf „' . $musicFile . '“.';
$errors[] = t('upload.audio_name_mismatch', ['actual' => $audioName, 'expected' => $musicFile]);
} else {
$sniffed = audio_sniff($audioTmp);
if ($sniffed === null) {
$errors[] = 'Die Audiodatei ist kein unterstütztes Format (MP3, OGG, WAV, M4A, AAC).';
$errors[] = t('upload.audio_format');
} else {
$audio = [
'tmp' => $audioTmp,
@ -542,9 +542,9 @@ function routine_send_file(array $routine, string $kind, ?array $user = null, bo
$revision = routine_fetch((int) $routine['id']);
if ($revision === null || $revision['revision_id'] === null) {
if ($api) {
abort_api(404, 'no_file', 'Diese Kür hat noch keine Datei.');
abort_api(404, 'no_file', t('routine.no_file_yet'));
}
abort_page(404, 'Diese Kür hat noch keine Datei.');
abort_page(404, t('routine.no_file_yet'));
}
if ($kind === 'audio') {
$path = (string) ($revision['audio_path'] ?? '');
@ -558,16 +558,16 @@ function routine_send_file(array $routine, string $kind, ?array $user = null, bo
$absolute = storage_path($path);
if ($path === '' || !is_file($absolute)) {
if ($api) {
abort_api(404, 'file_missing', 'Die Datei fehlt im Speicher.');
abort_api(404, 'file_missing', t('routine.file_missing'));
}
abort_page(404, 'Die Datei fehlt im Speicher.');
abort_page(404, t('routine.file_missing'));
}
$handle = fopen($absolute, 'rb');
if ($handle === false) {
if ($api) {
abort_api(500, 'file_unreadable', 'Die Datei konnte nicht geöffnet werden.');
abort_api(500, 'file_unreadable', t('routine.file_unreadable'));
}
abort_page(500, 'Die Datei konnte nicht geöffnet werden.');
abort_page(500, t('routine.file_unreadable'));
}
$user ??= auth_user();