Skip to content

Commit

Permalink
Wait for DOMContentLoaded until checking whether localization should …
Browse files Browse the repository at this point in the history
…be disabled

Refs AUTOMATIC1111#9955 (comment)
  • Loading branch information
akx committed May 13, 2023
1 parent 9080af5 commit 8d709ae
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions javascript/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,36 @@ function download_localization() {
document.body.removeChild(element);
}

if(hasLocalization()) {
onUiUpdate(function (m) {
m.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
processNode(node)
})
});
})


document.addEventListener("DOMContentLoaded", function () {
processNode(gradioApp())

if (localization.rtl) { // if the language is from right to left,
(new MutationObserver((mutations, observer) => { // wait for the style to load
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.tagName === 'STYLE') {
observer.disconnect();

for (const x of node.sheet.rules) { // find all rtl media rules
if (Array.from(x.media || []).includes('rtl')) {
x.media.appendMedium('all'); // enable them
}
}
}
})
});
})).observe(gradioApp(), { childList: true });
}
})
}
document.addEventListener("DOMContentLoaded", function () {
if (!hasLocalization()) {
return;
}

onUiUpdate(function (m) {
m.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
processNode(node)
})
});
})

processNode(gradioApp())

if (localization.rtl) { // if the language is from right to left,
(new MutationObserver((mutations, observer) => { // wait for the style to load
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.tagName === 'STYLE') {
observer.disconnect();

for (const x of node.sheet.rules) { // find all rtl media rules
if (Array.from(x.media || []).includes('rtl')) {
x.media.appendMedium('all'); // enable them
}
}
}
})
});
})).observe(gradioApp(), { childList: true });
}
})

0 comments on commit 8d709ae

Please sign in to comment.