Skip to content

Commit

Permalink
add new method to reuse localized text span, closes #8994
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd committed Apr 24, 2024
1 parent 2a5e8d4 commit 5251ee6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 18 additions & 0 deletions modules/core/localizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions modules/ui/note_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5251ee6

Please sign in to comment.