Skip to content

Commit 3d23885

Browse files
stable section translations (sans ellipsis)
1 parent fe7f7e5 commit 3d23885

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/Toolbar.js

+29
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,35 @@ class Toolbar {
452452
$jumpToInput.selectize({
453453
options: options,
454454
openOnFocus: true,
455+
render: {
456+
item: function (data, escape) {
457+
// Some `data.text` input is already prepended with spaces, so we replace the translation
458+
// ISSUE: a more consistent approach might use a formatter but this is simple. ;[prepend]indent
459+
460+
const item_name = data.value.replace(/\. /g, '').trim();
461+
const identifier_name = item_name.replace(/ /g, '_');
462+
const canonical_name = data.value.match(/ \. /g) ? identifier_name : item_name;
463+
const label = data.text.replace(item_name, i18next.t(canonical_name));
464+
465+
// TODO: not rerendering
466+
return `<div data-i18n='${canonical_name}'>` + escape(label) + `</div>`;
467+
},
468+
option: (data, escape) => {
469+
// Some `data.text` input is already prepended with spaces, so we replace the translation
470+
// ISSUE: a more consistent approach might use a formatter but this is simple. ;[prepend]indent
471+
472+
const item_name = data.value.replace(/\. /g, '').trim();
473+
const identifier_name = item_name.replace(/ /g, '_');
474+
const canonical_name = data.value.match(/ \. /g) ? identifier_name : item_name;
475+
const label = data.text.replace(item_name, i18next.t(canonical_name));
476+
477+
let indentation = 12 + label.search(/\S/) * 8; // pixels
478+
479+
return `<div style="padding-left:${indentation}px" class="option ${
480+
data.value === '' ? 'selectize-dropdown-emptyoptionlabel' : ''
481+
}" data-i18n='${canonical_name}'>${escape(label)}</div>`;
482+
},
483+
},
455484
});
456485
$jumpToInput.off('change').on('change', (e) => {
457486
if (!e.target.value) {

0 commit comments

Comments
 (0)