From 86ff43b930077aa41439c570fe41ad5de910455d Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Sat, 13 May 2023 19:44:55 +0300 Subject: [PATCH 1/4] Merge pull request #10335 from akx/l10n-dis-take-2 Localization fixes --- javascript/localization.js | 60 +++++++++++++++++++++----------------- modules/localization.py | 4 +-- modules/ui.py | 12 ++++---- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/javascript/localization.js b/javascript/localization.js index 0123b877b..86e5ca67c 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 + for (const text in original_lines) { + if(dumped[text] !== undefined) continue; + dumped[text] = localization[text] || text; + } - 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 }); + } +}) diff --git a/modules/localization.py b/modules/localization.py index f6a6f2fbd..ee9c65e7d 100644 --- a/modules/localization.py +++ b/modules/localization.py @@ -23,7 +23,7 @@ def list_localizations(dirname): localizations[fn] = file.path -def localization_js(current_localization_name): +def localization_js(current_localization_name: str) -> str: fn = localizations.get(current_localization_name, None) data = {} if fn is not None: @@ -34,4 +34,4 @@ def localization_js(current_localization_name): print(f"Error loading localization from {fn}:", file=sys.stderr) print(traceback.format_exc(), file=sys.stderr) - return f"var localization = {json.dumps(data)}\n" + return f"window.localization = {json.dumps(data)}" diff --git a/modules/ui.py b/modules/ui.py index d02f6e82c..f07bcc41e 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1863,12 +1863,11 @@ def webpath(fn): def javascript_html(): - script_js = os.path.join(script_path, "script.js") - head = f'\n' + # Ensure localization is in `window` before scripts + head = f'\n' - inline = f"{localization.localization_js(shared.opts.localization)};" - if cmd_opts.theme is not None: - inline += f"set_theme('{cmd_opts.theme}');" + script_js = os.path.join(script_path, "script.js") + head += f'\n' for script in modules.scripts.list_scripts("javascript", ".js"): head += f'\n' @@ -1876,7 +1875,8 @@ def javascript_html(): for script in modules.scripts.list_scripts("javascript", ".mjs"): head += f'\n' - head += f'\n' + if cmd_opts.theme: + head += f'\n' return head From d7e9ac2aff6bfd3c03f9d50a98e31468fd34a77f Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 13 May 2023 20:47:32 +0300 Subject: [PATCH 2/4] update readme --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b586b271c..a7bf4c2fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * fix upscalers disappearing after the user reloads UI * allow bf16 in safe unpickler (resolves problems with loading some loras) * allow web UI to be ran fully offline + * fix localizations not working ## 1.2.0 From b9abdb50a3684e2f7392bf68736ad1ec025045af Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 14 May 2023 13:31:03 +0300 Subject: [PATCH 3/4] add a possible fix for 'LatentDiffusion' object has no attribute 'lora_layer_mapping' --- CHANGELOG.md | 1 + extensions-builtin/Lora/lora.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7bf4c2fe..881870bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * allow bf16 in safe unpickler (resolves problems with loading some loras) * allow web UI to be ran fully offline * fix localizations not working + * fix error for loras: 'LatentDiffusion' object has no attribute 'lora_layer_mapping' ## 1.2.0 diff --git a/extensions-builtin/Lora/lora.py b/extensions-builtin/Lora/lora.py index 6fa800068..b5d0c98f9 100644 --- a/extensions-builtin/Lora/lora.py +++ b/extensions-builtin/Lora/lora.py @@ -133,6 +133,10 @@ def load_lora(name, filename): sd = sd_models.read_state_dict(filename) + # this should not be needed but is here as an emergency fix for an unknown error people are experiencing in 1.2.0 + if not hasattr(shared.sd_model, 'lora_layer_mapping'): + assign_lora_names_to_compvis_modules(shared.sd_model) + keys_failed_to_match = {} is_sd2 = 'model_transformer_resblocks' in shared.sd_model.lora_layer_mapping From dbd13dee3aa7c8e37aa43f30a8272b50ba61e7fe Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 14 May 2023 13:34:50 +0300 Subject: [PATCH 4/4] update readme for release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 881870bb9..8cf444ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## Upcoming 1.2.1 +## 1.2.1 ### Features: * add an option to always refer to lora by filenames