enhanced translation handling by ensuring source language inclusion and exposing German defaults for untranslated keys
This commit is contained in:
23
common.php
23
common.php
@ -888,13 +888,30 @@ 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) {
|
||||||
$result[$lang][$key] = $text;
|
if ($text !== '') {
|
||||||
|
$result[$lang][$key] = $text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!isset($result[QDB_SOURCE_LANGUAGE][$key]) && !empty($defaults[$key])) {
|
$defaultDe = trim($defaults[$key] ?? '');
|
||||||
$result[QDB_SOURCE_LANGUAGE][$key] = $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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
Reference in New Issue
Block a user