Make t function return a span element with a lang attribute unless html: false is specified in the options (re: #7963)

Update `text` functions to `html` to support inserting the `span` elements
Specify `html: false` for various instances where a `span` is not desired, e.g. `placeholder` and `title` attributes
This commit is contained in:
Quincy Morgan
2020-09-15 21:56:22 -04:00
parent 7aa6c1d1a3
commit 32f8274929
150 changed files with 471 additions and 463 deletions
+2 -2
View File
@@ -40,7 +40,7 @@ export function uiFieldAccess(field, context) {
.append('span')
.attr('class', 'label preset-label-access')
.attr('for', function(d) { return 'preset-input-access-' + d; })
.text(function(d) { return field.t('types.' + d); });
.html(function(d) { return field.t('types.' + d); });
enter
.append('div')
@@ -217,7 +217,7 @@ export function uiFieldAccess(field, context) {
})
.attr('placeholder', function(d) {
if (tags[d] && Array.isArray(tags[d])) {
return t('inspector.multiple_values');
return t('inspector.multiple_values', { html: false });
}
if (d === 'access') {
return 'yes';
+2 -2
View File
@@ -274,12 +274,12 @@ export function uiFieldAddress(field, context) {
function updatePlaceholder(inputSelection) {
return inputSelection.attr('placeholder', function(subfield) {
if (_tags && Array.isArray(_tags[field.key + ':' + subfield.id])) {
return t('inspector.multiple_values');
return t('inspector.multiple_values', { html: false });
}
if (_countryCode) {
var localkey = subfield.id + '!' + _countryCode;
var tkey = addrField.strings.placeholders[localkey] ? localkey : subfield.id;
return addrField.t('placeholders.' + tkey);
return addrField.t('placeholders.' + tkey, { html: false });
}
});
}
+3 -3
View File
@@ -83,7 +83,7 @@ export function uiFieldCheck(field, context) {
var icon = pseudoDirection ? '#iD-icon-forward' : '#iD-icon-backward';
selection.selectAll('.reverser-span')
.text(t('inspector.check.reverser'))
.html(t('inspector.check.reverser'))
.call(svgIcon(icon, 'inline'));
return selection;
@@ -108,7 +108,7 @@ export function uiFieldCheck(field, context) {
enter
.append('span')
.text(texts[0])
.html(texts[0])
.attr('class', 'value');
if (field.type === 'onewayCheck') {
@@ -212,7 +212,7 @@ export function uiFieldCheck(field, context) {
.property('checked', isChecked(_value));
text
.text(isMixed ? t('inspector.multiple_values') : textFor(_value))
.html(isMixed ? t('inspector.multiple_values') : textFor(_value))
.classed('mixed', isMixed);
label
+7 -7
View File
@@ -149,7 +149,7 @@ export function uiFieldCombo(field, context) {
if (optstrings) {
_comboData = Object.keys(optstrings).map(function(k) {
var v = field.t('options.' + k, { 'default': optstrings[k] });
var v = field.t('options.' + k, { 'default': optstrings[k], html: false });
return {
key: k,
value: v,
@@ -242,7 +242,7 @@ export function uiFieldCombo(field, context) {
function setPlaceholder(values) {
if (isMulti || isSemi) {
_staticPlaceholder = field.placeholder() || t('inspector.add');
_staticPlaceholder = field.placeholder() || t('inspector.add', { html: false });
} else {
var vals = values
.map(function(d) { return d.value; })
@@ -258,7 +258,7 @@ export function uiFieldCombo(field, context) {
var ph;
if (!isMulti && !isSemi && _tags && Array.isArray(_tags[field.key])) {
ph = t('inspector.multiple_values');
ph = t('inspector.multiple_values', { html: false });
} else {
ph = _staticPlaceholder;
}
@@ -528,7 +528,7 @@ export function uiFieldCombo(field, context) {
return d.isMixed;
})
.attr('title', function(d) {
return d.isMixed ? t('inspector.unshared_value_tooltip') : null;
return d.isMixed ? t('inspector.unshared_value_tooltip', { html: false }) : null;
});
if (allowDragAndDrop) {
@@ -536,12 +536,12 @@ export function uiFieldCombo(field, context) {
}
chips.select('span')
.text(function(d) { return d.value; });
.html(function(d) { return d.value; });
chips.select('a')
.on('click', removeMultikey)
.attr('class', 'remove')
.text('×');
.html('×');
} else {
var isMixed = Array.isArray(tags[field.key]);
@@ -552,7 +552,7 @@ export function uiFieldCombo(field, context) {
utilGetSetValue(input, !isMixed ? displayValue(tags[field.key]) : '')
.attr('title', isMixed ? mixedValues.join('\n') : undefined)
.attr('placeholder', isMixed ? t('inspector.multiple_values') : _staticPlaceholder || '')
.attr('placeholder', isMixed ? t('inspector.multiple_values', { html: false }) : _staticPlaceholder || '')
.classed('mixed', isMixed);
}
};
+2 -2
View File
@@ -49,7 +49,7 @@ export function uiFieldCycleway(field, context) {
.append('span')
.attr('class', 'label preset-label-cycleway')
.attr('for', function(d) { return 'preset-input-cycleway-' + stripcolon(d); })
.text(function(d) { return field.t('types.' + d); });
.html(function(d) { return field.t('types.' + d); });
enter
.append('div')
@@ -149,7 +149,7 @@ export function uiFieldCycleway(field, context) {
})
.attr('placeholder', function(d) {
if (Array.isArray(tags.cycleway) || Array.isArray(tags[d])) {
return t('inspector.multiple_values');
return t('inspector.multiple_values', { html: false });
}
return field.placeholder();
})
+2 -2
View File
@@ -113,7 +113,7 @@ export function uiFieldText(field, context) {
var domainResults = /^https?:\/\/(.{1,}?)\//.exec(field.urlFormat);
if (domainResults.length >= 2 && domainResults[1]) {
var domain = domainResults[1];
return t('icons.view_on', { domain: domain });
return t('icons.view_on', { domain: domain, html: false });
}
return '';
})
@@ -202,7 +202,7 @@ export function uiFieldText(field, context) {
utilGetSetValue(input, !isMixed && tags[field.key] ? tags[field.key] : '')
.attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : undefined)
.attr('placeholder', isMixed ? t('inspector.multiple_values') : (field.placeholder() || t('inspector.unknown')))
.attr('placeholder', isMixed ? t('inspector.multiple_values', { html: false }) : (field.placeholder() || t('inspector.unknown', { html: false })))
.classed('mixed', isMixed);
if (outlinkButton && !outlinkButton.empty()) {
+3 -3
View File
@@ -77,7 +77,7 @@ export function uiFieldLanes(field, context) {
.append('text')
.attr('y', 40)
.attr('x', 14)
.text('▲');
.html('▲');
enter
.append('g')
@@ -85,7 +85,7 @@ export function uiFieldLanes(field, context) {
.append('text')
.attr('y', 40)
.attr('x', 14)
.text('▲▼');
.html('▲▼');
enter
.append('g')
@@ -93,7 +93,7 @@ export function uiFieldLanes(field, context) {
.append('text')
.attr('y', 40)
.attr('x', 14)
.text('▼');
.html('▼');
lane = lane
+4 -4
View File
@@ -513,7 +513,7 @@ export function uiFieldLocalized(field, context) {
text
.append('span')
.attr('class', 'label-textvalue')
.text(t('translate.localized_translation_label'));
.html(t('translate.localized_translation_label'));
text
.append('span')
@@ -544,7 +544,7 @@ export function uiFieldLocalized(field, context) {
.attr('class', 'localized-lang')
.attr('id', domId)
.attr('type', 'text')
.attr('placeholder', t('translate.localized_translation_language'))
.attr('placeholder', t('translate.localized_translation_language', { html: false }))
.on('blur', changeLang)
.on('change', changeLang)
.call(langCombo);
@@ -591,7 +591,7 @@ export function uiFieldLocalized(field, context) {
return Array.isArray(d.value) ? d.value.filter(Boolean).join('\n') : null;
})
.attr('placeholder', function(d) {
return Array.isArray(d.value) ? t('inspector.multiple_values') : t('translate.localized_translation_name');
return Array.isArray(d.value) ? t('inspector.multiple_values', { html: false }) : t('translate.localized_translation_name', { html: false });
})
.classed('mixed', function(d) {
return Array.isArray(d.value);
@@ -618,7 +618,7 @@ export function uiFieldLocalized(field, context) {
utilGetSetValue(input, typeof tags[field.key] === 'string' ? tags[field.key] : '')
.attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : undefined)
.attr('placeholder', isMixed ? t('inspector.multiple_values') : field.placeholder())
.attr('placeholder', isMixed ? t('inspector.multiple_values', { html: false }) : field.placeholder())
.classed('mixed', isMixed);
calcMultilingual(tags);
+1 -1
View File
@@ -129,7 +129,7 @@ export function uiFieldMaxspeed(field, context) {
utilGetSetValue(input, typeof value === 'string' ? value : '')
.attr('title', isMixed ? value.filter(Boolean).join('\n') : null)
.attr('placeholder', isMixed ? t('inspector.multiple_values') : field.placeholder())
.attr('placeholder', isMixed ? t('inspector.multiple_values', { html: false }) : field.placeholder())
.classed('mixed', isMixed);
};
+7 -7
View File
@@ -59,12 +59,12 @@ export function uiFieldRadio(field, context) {
.append('input')
.attr('type', 'radio')
.attr('name', field.id)
.attr('value', function(d) { return field.t('options.' + d, { 'default': d }); })
.attr('value', function(d) { return field.t('options.' + d, { 'default': d, html: false }); })
.attr('checked', false);
enter
.append('span')
.text(function(d) { return field.t('options.' + d, { 'default': d }); });
.html(function(d) { return field.t('options.' + d, { 'default': d }); });
labels = labels
.merge(enter);
@@ -129,7 +129,7 @@ export function uiFieldRadio(field, context) {
.append('span')
.attr('class', 'label structure-label-type')
.attr('for', 'preset-input-' + selected)
.text(t('inspector.radio.structure.type'));
.html(t('inspector.radio.structure.type'));
typeEnter
.append('div')
@@ -174,7 +174,7 @@ export function uiFieldRadio(field, context) {
.append('span')
.attr('class', 'label structure-label-layer')
.attr('for', 'preset-input-layer')
.text(t('inspector.radio.structure.layer'));
.html(t('inspector.radio.structure.layer'));
layerEnter
.append('div')
@@ -290,16 +290,16 @@ export function uiFieldRadio(field, context) {
})
.classed('mixed', isMixed)
.attr('title', function(d) {
return isMixed(d) ? t('inspector.unshared_value_tooltip') : null;
return isMixed(d) ? t('inspector.unshared_value_tooltip', { html: false }) : null;
});
var selection = radios.filter(function() { return this.checked; });
if (selection.empty()) {
placeholder.text(t('inspector.none'));
placeholder.html(t('inspector.none'));
} else {
placeholder.text(selection.attr('value'));
placeholder.html(selection.attr('value'));
_oldType[selection.datum()] = tags[selection.datum()];
}
+6 -6
View File
@@ -124,7 +124,7 @@ export function uiFieldRestrictions(field, context) {
distControlEnter
.append('span')
.attr('class', 'restriction-control-label restriction-distance-label')
.text(t('restriction.controls.distance') + ':');
.html(t('restriction.controls.distance') + ':');
distControlEnter
.append('input')
@@ -151,7 +151,7 @@ export function uiFieldRestrictions(field, context) {
});
selection.selectAll('.restriction-distance-text')
.text(displayMaxDistance(_maxDistance));
.html(displayMaxDistance(_maxDistance));
var viaControl = selection.selectAll('.restriction-via-way')
@@ -167,7 +167,7 @@ export function uiFieldRestrictions(field, context) {
viaControlEnter
.append('span')
.attr('class', 'restriction-control-label restriction-via-way-label')
.text(t('restriction.controls.via') + ':');
.html(t('restriction.controls.via') + ':');
viaControlEnter
.append('input')
@@ -193,7 +193,7 @@ export function uiFieldRestrictions(field, context) {
});
selection.selectAll('.restriction-via-way-text')
.text(displayMaxVia(_maxViaWay));
.html(displayMaxVia(_maxViaWay));
}
@@ -517,7 +517,7 @@ export function uiFieldRestrictions(field, context) {
help
.append('div') // "NO Right Turn (indirect)"
.attr('class', 'qualifier ' + klass)
.text(turnText);
.html(turnText);
help
.append('div') // "FROM {fromName} TO {toName}"
@@ -548,7 +548,7 @@ export function uiFieldRestrictions(field, context) {
if (!indirect) {
help
.append('div') // Click for "No Right Turn"
.text(t('restriction.help.toggle', { turn: nextText.trim() }));
.html(t('restriction.help.toggle', { turn: nextText.trim() }));
}
highlightPathsFrom(null);
+1 -1
View File
@@ -61,7 +61,7 @@ export function uiFieldTextarea(field, context) {
utilGetSetValue(input, !isMixed && tags[field.key] ? tags[field.key] : '')
.attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : undefined)
.attr('placeholder', isMixed ? t('inspector.multiple_values') : (field.placeholder() || t('inspector.unknown')))
.attr('placeholder', isMixed ? t('inspector.multiple_values', { html: false }) : (field.placeholder() || t('inspector.unknown', { html: false })))
.classed('mixed', isMixed);
};
+4 -4
View File
@@ -93,7 +93,7 @@ export function uiFieldWikidata(field, context) {
searchRowEnter
.append('button')
.attr('class', 'form-field-button wiki-link')
.attr('title', t('icons.view_on', { domain: 'wikidata.org' }))
.attr('title', t('icons.view_on', { domain: 'wikidata.org', html: false }))
.attr('tabindex', -1)
.call(svgIcon('#iD-icon-out-link'))
.on('click', function() {
@@ -118,7 +118,7 @@ export function uiFieldWikidata(field, context) {
enter
.append('span')
.attr('class', 'label')
.text(function(d) { return t('wikidata.' + d); });
.html(function(d) { return t('wikidata.' + d); });
enter
.append('input')
@@ -130,7 +130,7 @@ export function uiFieldWikidata(field, context) {
enter
.append('button')
.attr('class', 'form-field-button')
.attr('title', t('icons.copy'))
.attr('title', t('icons.copy', { html: false }))
.attr('tabindex', -1)
.call(svgIcon('#iD-operation-copy'))
.on('click', function() {
@@ -292,7 +292,7 @@ export function uiFieldWikidata(field, context) {
var isMixed = Array.isArray(tags[field.key]);
_searchInput
.attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : null)
.attr('placeholder', isMixed ? t('inspector.multiple_values') : '')
.attr('placeholder', isMixed ? t('inspector.multiple_values', { html: false }) : '')
.classed('mixed', isMixed);
_qid = typeof tags[field.key] === 'string' && tags[field.key] || '';
+2 -2
View File
@@ -87,7 +87,7 @@ export function uiFieldWikipedia(field, context) {
.append('input')
.attr('type', 'text')
.attr('class', 'wiki-lang')
.attr('placeholder', t('translate.localized_translation_language'))
.attr('placeholder', t('translate.localized_translation_language', { html: false }))
.call(utilNoAuto)
.call(langCombo)
.merge(_langInput);
@@ -129,7 +129,7 @@ export function uiFieldWikipedia(field, context) {
.append('button')
.attr('class', 'form-field-button wiki-link')
.attr('tabindex', -1)
.attr('title', t('icons.view_on', { domain: 'wikipedia.org' }))
.attr('title', t('icons.view_on', { domain: 'wikipedia.org', html: false }))
.call(svgIcon('#iD-icon-out-link'))
.merge(link);