refactored translation mapping logic to streamline default handling and restricted option assignment based on layout type

This commit is contained in:
2026-05-27 15:15:39 +02:00
parent e8f92cc6ca
commit 5a2faa3ecc
2 changed files with 8 additions and 22 deletions

View File

@ -888,30 +888,13 @@ function qdb_build_app_translations_map(PDO $pdo): array {
$translations = qdb_load_translations_for_entries($pdo, $entries);
$defaults = qdb_app_string_catalog()['germanDefaults'] ?? [];
$result = [];
qdb_ensure_source_language($pdo);
$languageCodes = $pdo->query('SELECT languageCode FROM language ORDER BY languageCode')
->fetchAll(PDO::FETCH_COLUMN);
if (!in_array(QDB_SOURCE_LANGUAGE, $languageCodes, true)) {
$languageCodes[] = QDB_SOURCE_LANGUAGE;
}
foreach ($entries as $e) {
$key = $e['key'];
foreach ($translations[$e['entityId']] ?? [] as $lang => $text) {
if ($text !== '') {
$result[$lang][$key] = $text;
}
$result[$lang][$key] = $text;
}
$defaultDe = trim($defaults[$key] ?? '');
if ($defaultDe === '') {
continue;
}
// New catalog keys: expose German default for every language until translated on the website.
foreach ($languageCodes as $lc) {
if (empty($result[$lc][$key] ?? '')) {
$result[$lc][$key] = $defaultDe;
}
if (!isset($result[QDB_SOURCE_LANGUAGE][$key]) && !empty($defaults[$key])) {
$result[QDB_SOURCE_LANGUAGE][$key] = $defaults[$key];
}
}
return $result;

View File

@ -339,8 +339,11 @@ if ($qnID) {
$optionsArr[] = $o;
$pointsMap[$opt['defaultText']] = (int)$opt['points'];
}
$q['options'] = $optionsArr;
$q['pointsMap'] = $pointsMap;
// DB answer_option rows are for choice layouts only — do not overwrite string/value spinners.
if (in_array($layout, ['radio_question', 'multi_check_box_question', 'glass_scale_question'], true)) {
$q['options'] = $optionsArr;
$q['pointsMap'] = $pointsMap;
}
}
$questions[] = $q;