diff --git a/javascript/bilingual_localization.js b/javascript/bilingual_localization.js index 0534f60..e246de7 100644 --- a/javascript/bilingual_localization.js +++ b/javascript/bilingual_localization.js @@ -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