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);
|
$translations = qdb_load_translations_for_entries($pdo, $entries);
|
||||||
$defaults = qdb_app_string_catalog()['germanDefaults'] ?? [];
|
$defaults = qdb_app_string_catalog()['germanDefaults'] ?? [];
|
||||||
$result = [];
|
$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) {
|
foreach ($entries as $e) {
|
||||||
$key = $e['key'];
|
$key = $e['key'];
|
||||||
foreach ($translations[$e['entityId']] ?? [] as $lang => $text) {
|
foreach ($translations[$e['entityId']] ?? [] as $lang => $text) {
|
||||||
if ($text !== '') {
|
$result[$lang][$key] = $text;
|
||||||
$result[$lang][$key] = $text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$defaultDe = trim($defaults[$key] ?? '');
|
if (!isset($result[QDB_SOURCE_LANGUAGE][$key]) && !empty($defaults[$key])) {
|
||||||
if ($defaultDe === '') {
|
$result[QDB_SOURCE_LANGUAGE][$key] = $defaults[$key];
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@ -339,8 +339,11 @@ if ($qnID) {
|
|||||||
$optionsArr[] = $o;
|
$optionsArr[] = $o;
|
||||||
$pointsMap[$opt['defaultText']] = (int)$opt['points'];
|
$pointsMap[$opt['defaultText']] = (int)$opt['points'];
|
||||||
}
|
}
|
||||||
$q['options'] = $optionsArr;
|
// DB answer_option rows are for choice layouts only — do not overwrite string/value spinners.
|
||||||
$q['pointsMap'] = $pointsMap;
|
if (in_array($layout, ['radio_question', 'multi_check_box_question', 'glass_scale_question'], true)) {
|
||||||
|
$q['options'] = $optionsArr;
|
||||||
|
$q['pointsMap'] = $pointsMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$questions[] = $q;
|
$questions[] = $q;
|
||||||
|
|||||||
Reference in New Issue
Block a user