From 0c1c9e74cda6637ab1305b4c294b7719eb141927 Mon Sep 17 00:00:00 2001 From: liubo0902 <38622806+liubo0902@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:06:47 +0800 Subject: [PATCH 1/3] Update localization.py --- modules/localization.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/localization.py b/modules/localization.py index c13202885..3392b0557 100644 --- a/modules/localization.py +++ b/modules/localization.py @@ -1,7 +1,7 @@ import json import os -from modules import errors, scripts +from modules import errors localizations = {} @@ -14,21 +14,27 @@ def list_localizations(dirname): if ext.lower() != ".json": continue - localizations[fn] = os.path.join(dirname, file) + fn = fn.replace(" ", "").replace("(", "_").replace(")","") + localizations[fn] = [os.path.join(dirname, file)] + from modules import scripts for file in scripts.list_scripts("localizations", ".json"): fn, ext = os.path.splitext(file.filename) - localizations[fn] = file.path + fn = fn.replace(" ", "").replace("(", "_").replace(")","") + if fn not in localizations: + localizations[fn] = [] + localizations[fn].append(file.path) def localization_js(current_localization_name: str) -> str: - fn = localizations.get(current_localization_name, None) + fns = localizations.get(current_localization_name, None) data = {} - if fn is not None: - try: - with open(fn, "r", encoding="utf8") as file: - data = json.load(file) - except Exception: - errors.report(f"Error loading localization from {fn}", exc_info=True) + if fns is not None: + for fn in fns: + try: + with open(fn, "r", encoding="utf8") as file: + data.update(json.load(file)) + except Exception: + errors.report(f"Error loading localization from {fn}", exc_info=True) return f"window.localization = {json.dumps(data)}" From ff7027ffc075ae44ddaa56014f900d392cf53ca8 Mon Sep 17 00:00:00 2001 From: liubo0902 <38622806+liubo0902@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:08:59 +0800 Subject: [PATCH 2/3] Update localization.py --- modules/localization.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/localization.py b/modules/localization.py index 3392b0557..262d49ee1 100644 --- a/modules/localization.py +++ b/modules/localization.py @@ -1,7 +1,7 @@ import json import os -from modules import errors +from modules import errors, scripts localizations = {} @@ -17,7 +17,6 @@ def list_localizations(dirname): fn = fn.replace(" ", "").replace("(", "_").replace(")","") localizations[fn] = [os.path.join(dirname, file)] - from modules import scripts for file in scripts.list_scripts("localizations", ".json"): fn, ext = os.path.splitext(file.filename) fn = fn.replace(" ", "").replace("(", "_").replace(")","") From 413123f08a745e9417fd384d2c1bee1e0e5e5730 Mon Sep 17 00:00:00 2001 From: liubo0902 <38622806+liubo0902@users.noreply.github.com> Date: Mon, 11 Sep 2023 09:22:27 +0800 Subject: [PATCH 3/3] Update localization.py --- modules/localization.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/localization.py b/modules/localization.py index 262d49ee1..108f792e9 100644 --- a/modules/localization.py +++ b/modules/localization.py @@ -14,12 +14,10 @@ def list_localizations(dirname): if ext.lower() != ".json": continue - fn = fn.replace(" ", "").replace("(", "_").replace(")","") localizations[fn] = [os.path.join(dirname, file)] for file in scripts.list_scripts("localizations", ".json"): fn, ext = os.path.splitext(file.filename) - fn = fn.replace(" ", "").replace("(", "_").replace(")","") if fn not in localizations: localizations[fn] = [] localizations[fn].append(file.path)