refactored translation mapping logic to streamline default handling and restricted option assignment based on layout type
This commit is contained in:
23
common.php
23
common.php
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user