add new method to reuse localized text span, closes #8994

This commit is contained in:
Martin Raifer
2024-04-24 16:13:18 +02:00
parent 2a5e8d4243
commit 5251ee6b65
2 changed files with 20 additions and 4 deletions
+18
View File
@@ -399,6 +399,24 @@ export function coreLocalizer() {
return ret;
};
// Adds or updates a localized text wrapped as an HTML span element with locale info to the DOM
localizer.t.addOrUpdate = function(stringId, replacements, locale) {
const ret = function(selection) {
const info = localizer.tInfo(stringId, replacements, locale);
const span = selection.selectAll('span.localized-text').data([info]);
const enter = span.enter()
.append('span')
.classed('localized-text', true);
span.merge(enter)
.attr('lang', info.locale || 'und')
.text((replacements && replacements.prefix || '')
+ info.text
+ (replacements &&replacements.suffix || ''));
};
ret.stringId = stringId;
return ret;
};
localizer.languageName = (code, options) => {
if (_languageNames && _languageNames[code]) { // name in locale language
+2 -4
View File
@@ -371,13 +371,11 @@ export function uiNoteEditor(context) {
buttonSection.select('.status-button') // select and propagate data
.attr('disabled', (hasAuth ? null : true))
.text('')
.each(function(d) {
var action = (d.status === 'open' ? 'close' : 'open');
var andComment = (d.newComment ? '_comment' : '');
t.append('note.' + action + andComment)(d3_select(this));
});
buttonSection.select('.status-button')
t.addOrUpdate('note.' + action + andComment)(d3_select(this));
})
.on('click.status', clickStatus);
buttonSection.select('.comment-button') // select and propagate data