fix: translate only static strings in unread drawer menu

Translating menuEl.innerHTML re-serialized untrusted topic titles into
HTML and reinjected them via innerHTML. Translate only the two static
placeholder strings ([[unread:no-unread-topics]], [[unread:title]])
via a small textContent-based helper instead.
This commit is contained in:
2026-07-17 18:17:30 +02:00
parent d84b264150
commit 6dca9b61b1
+12 -8
View File
@@ -159,6 +159,16 @@
}); });
} }
function translateText(el) {
if (window.require) {
window.require(['translator'], function (translator) {
translator.translate(el.textContent, (translated) => {
el.textContent = translated;
});
});
}
}
function renderUnreadMenu(menuEl, topics) { function renderUnreadMenu(menuEl, topics) {
if (!menuEl) { if (!menuEl) {
return; return;
@@ -179,6 +189,7 @@
empty.className = 'dropdown-item disabled'; empty.className = 'dropdown-item disabled';
empty.textContent = '[[unread:no-unread-topics]]'; empty.textContent = '[[unread:no-unread-topics]]';
addItem(empty); addItem(empty);
translateText(empty);
} }
list.forEach((topic) => { list.forEach((topic) => {
@@ -204,14 +215,7 @@
seeAll.href = `${relativePath}/unread`; seeAll.href = `${relativePath}/unread`;
seeAll.textContent = '[[unread:title]]'; seeAll.textContent = '[[unread:title]]';
addItem(seeAll); addItem(seeAll);
translateText(seeAll);
if (window.require) {
window.require(['translator'], function (translator) {
translator.translate(menuEl.innerHTML, (translated) => {
menuEl.innerHTML = translated;
});
});
}
} }
function getWestgateTopbar() { function getWestgateTopbar() {