fix: Dropdown menu displays incorrectly, fixes #24
Fix the issue where the dropdown menu displays incorrectly as `__biligual__will_be_replaced__` when bilingual is disabled.dev
parent
e664064b07
commit
3b89efca31
|
|
@ -128,6 +128,29 @@
|
|||
logger.groupEnd()
|
||||
|
||||
translatePage()
|
||||
handleDropdown()
|
||||
}
|
||||
|
||||
function handleDropdown() {
|
||||
// process gradio dropdown menu
|
||||
delegateEvent(gradioApp(), 'mousedown', 'ul.options .item', function (event) {
|
||||
const { target } = event
|
||||
|
||||
if (!target.classList.contains('item')) {
|
||||
// simulate click menu item
|
||||
target.closest('.item').dispatchEvent(new Event('mousedown', { bubbles: true }))
|
||||
return
|
||||
}
|
||||
|
||||
const source = target.dataset.value
|
||||
const $labelEl = target?.closest('.wrap')?.querySelector('.wrap-inner .single-select') // the label element
|
||||
|
||||
if (source && $labelEl) {
|
||||
$labelEl.title = titles?.[source] || '' // set title from hints.js
|
||||
$labelEl.textContent = "__biligual__will_be_replaced__" // marked as will be replaced
|
||||
doTranslate($labelEl, source, 'element') // translate the label element
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Translate page
|
||||
|
|
@ -467,29 +490,6 @@
|
|||
attributes: true,
|
||||
attributeFilter: ['title', 'placeholder']
|
||||
})
|
||||
|
||||
// process gradio dropdown menu
|
||||
delegateEvent(gradioApp(), 'mousedown', 'ul.options .item', function (event) {
|
||||
if (Object.keys(localization).length) return; // disabled if original translation enabled
|
||||
if (Object.keys(opts).length === 0) return; // does nothing if opts is not loaded
|
||||
|
||||
const { target } = event
|
||||
|
||||
if (!target.classList.contains('item')) {
|
||||
// simulate click menu item
|
||||
target.closest('.item').dispatchEvent(new Event('mousedown', { bubbles: true }))
|
||||
return
|
||||
}
|
||||
|
||||
const source = target.dataset.value
|
||||
const $labelEl = target?.closest('.wrap')?.querySelector('.wrap-inner .single-select') // the label element
|
||||
|
||||
if (source && $labelEl) {
|
||||
$labelEl.title = titles[source] || '' // set title from hints.js
|
||||
$labelEl.textContent = "__biligual__will_be_replaced__" // marked as will be replaced
|
||||
doTranslate($labelEl, source, 'element') // translate the label element
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Init after page loaded
|
||||
|
|
|
|||
Loading…
Reference in New Issue