diff options
author | AUTOMATIC <16777216c@gmail.com> | 2023-05-14 10:35:07 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2023-05-14 10:35:07 +0000 |
commit | 89f9faa63388756314e8a1d96cf86bf5e0663045 (patch) | |
tree | 86c94057a383c3665f994c0c9ce0c5205deec14f /javascript/localization.js | |
parent | b08500cec8a791ef20082628b49b17df833f5dda (diff) | |
parent | dbd13dee3aa7c8e37aa43f30a8272b50ba61e7fe (diff) | |
download | stable-diffusion-webui-gfx803-89f9faa63388756314e8a1d96cf86bf5e0663045.tar.gz stable-diffusion-webui-gfx803-89f9faa63388756314e8a1d96cf86bf5e0663045.tar.bz2 stable-diffusion-webui-gfx803-89f9faa63388756314e8a1d96cf86bf5e0663045.zip |
Merge branch 'release_candidate'
Diffstat (limited to 'javascript/localization.js')
-rw-r--r-- | javascript/localization.js | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/javascript/localization.js b/javascript/localization.js index 0123b877..86e5ca67 100644 --- a/javascript/localization.js +++ b/javascript/localization.js @@ -109,18 +109,23 @@ function processNode(node){ }
function dumpTranslations(){
+ if(!hasLocalization()) {
+ // If we don't have any localization,
+ // we will not have traversed the app to find
+ // original_lines, so do that now.
+ processNode(gradioApp());
+ }
var dumped = {}
if (localization.rtl) {
- dumped.rtl = true
+ dumped.rtl = true;
}
- Object.keys(original_lines).forEach(function(text){
- if(dumped[text] !== undefined) return
-
- dumped[text] = localization[text] || text
- })
+ for (const text in original_lines) {
+ if(dumped[text] !== undefined) continue;
+ dumped[text] = localization[text] || text;
+ }
- return dumped
+ return dumped;
}
function download_localization() {
@@ -137,7 +142,11 @@ function download_localization() { document.body.removeChild(element);
}
-if(hasLocalization()) {
+document.addEventListener("DOMContentLoaded", function () {
+ if (!hasLocalization()) {
+ return;
+ }
+
onUiUpdate(function (m) {
m.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
@@ -146,26 +155,23 @@ if(hasLocalization()) { });
})
+ processNode(gradioApp())
- 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();
- 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
- }
+ 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 });
- }
- })
-}
+ }
+ })
+ });
+ })).observe(gradioApp(), { childList: true });
+ }
+})
|