From 479586be37ba7a106b70626605e55f9f6c865484 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 9 Dec 2022 19:34:13 +0100 Subject: [PATCH] combo boxes can consume complex label strings now: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of `"strings": { "options": { "": "", …` it is now also supported to have: ``` "strings": { "options": { "": { "title": "", "description": "" }, … ``` --- modules/ui/fields/combo.js | 39 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 7cdfa43e7..827a5d9f8 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -121,8 +121,9 @@ export function uiFieldCombo(field, context) { tval = tval || ''; var stringsField = field.resolveReference('stringsCrossReference'); - if (stringsField.hasTextForStringId('options.' + tval)) { - return stringsField.t('options.' + tval, { default: tval }); + const labelId = stringsField.hasTextForStringId(`options.${tval}.title`) ? `options.${tval}.title` : `options.${tval}`; + if (stringsField.hasTextForStringId(labelId)) { + return stringsField.t(labelId, { default: tval }); } if (field.type === 'typeCombo' && tval.toLowerCase() === 'yes') { @@ -139,8 +140,9 @@ export function uiFieldCombo(field, context) { tval = tval || ''; var stringsField = field.resolveReference('stringsCrossReference'); - if (stringsField.hasTextForStringId('options.' + tval)) { - return stringsField.t.append('options.' + tval, { default: tval }); + const labelId = stringsField.hasTextForStringId(`options.${tval}.title`) ? `options.${tval}.title` : `options.${tval}`; + if (stringsField.hasTextForStringId(labelId)) { + return stringsField.t(labelId, { default: tval }); } if (field.type === 'typeCombo' && tval.toLowerCase() === 'yes') { @@ -184,12 +186,14 @@ export function uiFieldCombo(field, context) { if (!(field.options || stringsField.options)) return []; return (field.options || stringsField.options).map(function(v) { + const labelId = stringsField.hasTextForStringId(`options.${v}.title`) ? `options.${v}.title` : `options.${v}`; + const hasDescription = stringsField.hasTextForStringId(`options.${v}.description`); return { key: v, - value: stringsField.t('options.' + v, { default: v }), - title: v, - display: addComboboxIcons(stringsField.t.append('options.' + v, { default: v }), v), - klass: stringsField.hasTextForStringId('options.' + v) ? '' : 'raw-option' + value: stringsField.t(labelId, { default: v }), + title: stringsField.t(`options.${v}.description`, { default: v }), + display: addComboboxIcons(stringsField.t.append(labelId, { default: v }), v), + klass: stringsField.hasTextForStringId(labelId) ? '' : 'raw-option' }; }); } @@ -266,15 +270,17 @@ export function uiFieldCombo(field, context) { _container.classed('empty-combobox', data.length === 0); _comboData = data.concat(additionalOptions).map(function(d) { - var k = d.value; - if (_isMulti) k = k.replace(field.key, ''); - var isLocalizable = stringsField.hasTextForStringId('options.' + k); - var label = stringsField.t('options.' + k, { default: k }); + var v = d.value; + if (_isMulti) v = v.replace(field.key, ''); + const labelId = stringsField.hasTextForStringId(`options.${v}.title`) ? `options.${v}.title` : `options.${v}`; + var isLocalizable = stringsField.hasTextForStringId(labelId); + var label = stringsField.t(labelId, { default: v }); return { - key: k, + key: v, value: label, - display: addComboboxIcons(stringsField.t.append('options.' + k, { default: k }), k), - title: isLocalizable ? k : (d.title !== label ? d.title : ''), + title: stringsField.t(`options.${v}.description`, { default: + isLocalizable ? v : (d.title !== label ? d.title : '') }), + display: addComboboxIcons(stringsField.t.append(labelId, { default: v }), v), klass: isLocalizable ? '' : 'raw-option' }; }); @@ -684,7 +690,8 @@ export function uiFieldCombo(field, context) { }).filter(Boolean); var showsValue = !isMixed && tags[field.key] && !(field.type === 'typeCombo' && tags[field.key] === 'yes'); - var isRawValue = showsValue && !stringsField.hasTextForStringId('options.' + tags[field.key]); + var isRawValue = showsValue && !stringsField.hasTextForStringId(`options.${tags[field.key]}`) + && !stringsField.hasTextForStringId(`options.${tags[field.key]}.title`); var isKnownValue = showsValue && !isRawValue; var isReadOnly = !_allowCustomValues || isKnownValue;