From 5251ee6b65937382da963f6969e2435064d83ce4 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Wed, 24 Apr 2024 16:13:18 +0200 Subject: [PATCH] add new method to reuse localized text span, closes #8994 --- modules/core/localizer.js | 18 ++++++++++++++++++ modules/ui/note_editor.js | 6 ++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/core/localizer.js b/modules/core/localizer.js index f275eefd3..1637c5d86 100644 --- a/modules/core/localizer.js +++ b/modules/core/localizer.js @@ -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 diff --git a/modules/ui/note_editor.js b/modules/ui/note_editor.js index 1a462e662..8f9c0f391 100644 --- a/modules/ui/note_editor.js +++ b/modules/ui/note_editor.js @@ -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