fixed translation bug

This commit is contained in:
2026-05-22 17:18:14 +02:00
parent 472e45d730
commit be01b85569
4 changed files with 58 additions and 22 deletions

View File

@ -279,10 +279,11 @@ function qdb_app_ui_string_entries(): array {
$order = 0;
foreach ($catalog['keys'] ?? [] as $key) {
$entries[] = [
'key' => $key,
'type' => 'app_string',
'entityId' => $key,
'sortOrder' => $order++,
'key' => $key,
'displayKey' => $key,
'type' => 'app_string',
'entityId' => $key,
'sortOrder' => $order++,
'germanDefault' => $defaults[$key] ?? $key,
];
}
@ -382,6 +383,24 @@ function qdb_put_translation(PDO $pdo, string $type, string $id, string $lang, s
}
}
/** Short label for translation UI (Key column); full text stays in `key` for API lookup. */
function qdb_translation_display_key(array $e): string {
if (!empty($e['displayKey'])) {
return $e['displayKey'];
}
if (($e['type'] ?? '') === 'question' || ($e['type'] ?? '') === 'answer_option') {
$id = $e['entityId'] ?? '';
$pos = strrpos($id, '__');
return $pos !== false ? substr($id, $pos + 2) : $id;
}
return $e['key'] ?? '';
}
function qdb_short_entity_label(string $entityId): string {
$pos = strrpos($entityId, '__');
return $pos !== false ? substr($entityId, $pos + 2) : $entityId;
}
function qdb_require_non_empty_german(string $text, string $label = 'German text'): void {
if ($text === '') {
json_error('MISSING_FIELDS', "$label is required", 400);
@ -407,10 +426,11 @@ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array {
foreach ($dbQuestions as $dbQ) {
$qOrder = (int)($dbQ['orderIndex'] ?? 0);
$contentEntries[] = [
'key' => $dbQ['defaultText'],
'type' => 'question',
'entityId' => $dbQ['questionID'],
'sortOrder' => $qOrder * 1000,
'key' => $dbQ['defaultText'],
'displayKey' => qdb_short_entity_label($dbQ['questionID']),
'type' => 'question',
'entityId' => $dbQ['questionID'],
'sortOrder' => $qOrder * 1000,
];
$aoStmt = $pdo->prepare("
@ -420,10 +440,11 @@ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array {
$aoStmt->execute([':qid' => $dbQ['questionID']]);
foreach ($aoStmt->fetchAll(PDO::FETCH_ASSOC) as $ao) {
$contentEntries[] = [
'key' => $ao['defaultText'],
'type' => 'answer_option',
'entityId' => $ao['answerOptionID'],
'sortOrder' => $qOrder * 1000 + 10 + (int)($ao['orderIndex'] ?? 0),
'key' => $ao['defaultText'],
'displayKey' => qdb_short_entity_label($ao['answerOptionID']),
'type' => 'answer_option',
'entityId' => $ao['answerOptionID'],
'sortOrder' => $qOrder * 1000 + 10 + (int)($ao['orderIndex'] ?? 0),
];
}
@ -449,10 +470,11 @@ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array {
continue;
}
$stringEntries[] = [
'key' => $sk,
'type' => 'string',
'entityId' => $sk,
'sortOrder' => $stringOrder++,
'key' => $sk,
'displayKey' => $sk,
'type' => 'string',
'entityId' => $sk,
'sortOrder' => $stringOrder++,
];
}