diff --git a/modules/localization.py b/modules/localization.py
index f6a6f2fb..ee9c65e7 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 ff82fff6..ff25c4ce 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -1771,12 +1771,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'
@@ -1784,7 +1783,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