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:
+12
-8
@@ -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) {
|
||||
if (!menuEl) {
|
||||
return;
|
||||
@@ -179,6 +189,7 @@
|
||||
empty.className = 'dropdown-item disabled';
|
||||
empty.textContent = '[[unread:no-unread-topics]]';
|
||||
addItem(empty);
|
||||
translateText(empty);
|
||||
}
|
||||
|
||||
list.forEach((topic) => {
|
||||
@@ -204,14 +215,7 @@
|
||||
seeAll.href = `${relativePath}/unread`;
|
||||
seeAll.textContent = '[[unread:title]]';
|
||||
addItem(seeAll);
|
||||
|
||||
if (window.require) {
|
||||
window.require(['translator'], function (translator) {
|
||||
translator.translate(menuEl.innerHTML, (translated) => {
|
||||
menuEl.innerHTML = translated;
|
||||
});
|
||||
});
|
||||
}
|
||||
translateText(seeAll);
|
||||
}
|
||||
|
||||
function getWestgateTopbar() {
|
||||
|
||||
Reference in New Issue
Block a user