Skip to content

Commit

Permalink
stable section translations (sans ellipsis)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Feb 7, 2024
1 parent fe7f7e5 commit 3d23885
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,35 @@ class Toolbar {
$jumpToInput.selectize({
options: options,
openOnFocus: true,
render: {
item: function (data, escape) {
// Some `data.text` input is already prepended with spaces, so we replace the translation
// ISSUE: a more consistent approach might use a formatter but this is simple. ;[prepend]indent

const item_name = data.value.replace(/\. /g, '').trim();
const identifier_name = item_name.replace(/ /g, '_');
const canonical_name = data.value.match(/ \. /g) ? identifier_name : item_name;
const label = data.text.replace(item_name, i18next.t(canonical_name));

// TODO: not rerendering
return `<div data-i18n='${canonical_name}'>` + escape(label) + `</div>`;
},
option: (data, escape) => {
// Some `data.text` input is already prepended with spaces, so we replace the translation
// ISSUE: a more consistent approach might use a formatter but this is simple. ;[prepend]indent

const item_name = data.value.replace(/\. /g, '').trim();
const identifier_name = item_name.replace(/ /g, '_');
const canonical_name = data.value.match(/ \. /g) ? identifier_name : item_name;
const label = data.text.replace(item_name, i18next.t(canonical_name));

let indentation = 12 + label.search(/\S/) * 8; // pixels

return `<div style="padding-left:${indentation}px" class="option ${
data.value === '' ? 'selectize-dropdown-emptyoptionlabel' : ''
}" data-i18n='${canonical_name}'>${escape(label)}</div>`;
},
},
});
$jumpToInput.off('change').on('change', (e) => {
if (!e.target.value) {
Expand Down

0 comments on commit 3d23885

Please sign in to comment.