add locale override capabilities

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-02-09 09:27:04 -05:00
parent a34d331967
commit d01fefdb30
9 changed files with 37 additions and 12 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
# Change Log for SD.Next
## Update for 2025-02-08
## Update for 2025-02-09
- **Hints**
- added/updated 100+ ui hints!
@@ -8,7 +8,7 @@
- **Localization**
- full ui localization!
english, croatian, spanish, french, italian, portuguese, chinese, japanese, korean, russian
- set in *settings -> user interface -> language*
- set in *settings -> user interface -> language*
- [localization](https://github.com/vladmandic/wiki/Locale) documentation
- **Torch**:
- for **zluda** set default to `torch==2.6.0+cu118`
+2
View File
@@ -0,0 +1,2 @@
[
]
+3
View File
@@ -0,0 +1,3 @@
[
{ "id": "", "label": "Reprocess", "localized": "Ponovi", "hint": "Ponovno obradite prethodne generacije koristeći različite parametre" }
]
+4
View File
@@ -0,0 +1,4 @@
[
{ "id": "", "label": "🎲️", "localized": "", "hint": "무작위 시드 사용" },
{ "id": "", "label": "🔄", "localized": "", "hint": "초기화" }
]
+20 -7
View File
@@ -11,7 +11,7 @@ const localeData = {
};
async function cycleLocale() {
console.log('cycleLocale', localeData.prev, localeData.locale);
log('cycleLocale', localeData.prev, localeData.locale);
const index = allLocales.indexOf(localeData.prev);
localeData.locale = allLocales[(index + 1) % allLocales.length];
localeData.btn.innerText = localeData.locale;
@@ -129,12 +129,22 @@ async function getLocaleData(desiredLocale = null) {
localeData.prev = localeData.locale;
}
log('getLocale', desiredLocale, localeData.locale);
let res = await fetch(`/file=html/locale_${localeData.locale}.json`);
if (!res || !res.ok) {
localeData.locale = 'en';
res = await fetch(`/file=html/locale_${localeData.locale}.json`);
}
const json = await res.json();
// primary
let json = {};
try {
let res = await fetch(`/file=html/locale_${localeData.locale}.json`);
if (!res || !res.ok) {
localeData.locale = 'en';
res = await fetch(`/file=html/locale_${localeData.locale}.json`);
}
json = await res.json();
} catch { /**/ }
try {
const res = await fetch(`/file=html/override_${localeData.locale}.json`);
if (res && res.ok) json.override = await res.json();
} catch { /**/ }
return json;
}
@@ -150,7 +160,10 @@ async function setHints(analyze = false) {
if (elements.length === 0) return;
if (localeData.data.length === 0) {
json = await getLocaleData(window.opts.ui_locale);
let overrideData = json.override || {};
overrideData = Object.values(overrideData).flat().filter((e) => e.hint.length > 0);
localeData.data = Object.values(json).flat().filter((e) => e.hint.length > 0);
Object.assign(localeData.data, overrideData);
for (const e of localeData.data) e.label = e.label.toLowerCase().trim();
}
if (!localeData.hint) tooltipCreate();
+2
View File
@@ -71,6 +71,8 @@ def setup_middleware(app: FastAPI, cmd_opts):
}
if err['code'] == 401 and 'file=' in req.url.path: # dont spam with unauth
return JSONResponse(status_code=err['code'], content=jsonable_encoder(err))
if err['code'] == 404 and 'file=html/' in req.url.path: # dont spam with locales
return JSONResponse(status_code=err['code'], content=jsonable_encoder(err))
log.error(f"API error: {req.method}: {req.url} {err}")
+1 -2
View File
@@ -39,6 +39,7 @@ def main_args():
group_http = parser.add_argument_group('HTTP')
group_http.add_argument('--theme', type=str, default=os.environ.get("SD_THEME", None), help='Override UI theme')
group_http.add_argument('--locale', type=str, default=os.environ.get("SD_LOCALE", None), help='Override UI locale')
group_http.add_argument("--server-name", type=str, default=os.environ.get("SD_SERVERNAME", None), help="Sets hostname of server, default: %(default)s")
group_http.add_argument("--tls-keyfile", type=str, default=os.environ.get("SD_TLSKEYFILE", None), help="Enable TLS and specify key file, default: %(default)s")
group_http.add_argument("--tls-certfile", type=str, default=os.environ.get("SD_TLSCERTFILE", None), help="Enable TLS and specify cert file, default: %(default)s")
@@ -68,7 +69,6 @@ def compatibility_args():
group_compat.add_argument("--ui-settings-file", type=str, help=argparse.SUPPRESS, default=os.path.join(data_path, 'config.json'))
group_compat.add_argument("--ui-config-file", type=str, help=argparse.SUPPRESS, default=os.path.join(data_path, 'ui-config.json'))
group_compat.add_argument("--hide-ui-dir-config", action='store_true', help=argparse.SUPPRESS, default=False)
group_compat.add_argument("--theme", type=str, help=argparse.SUPPRESS, default=None)
group_compat.add_argument("--disable-console-progressbars", action='store_true', help=argparse.SUPPRESS, default=True)
group_compat.add_argument("--disable-safe-unpickle", action='store_true', help=argparse.SUPPRESS, default=True)
group_compat.add_argument("--lowram", action='store_true', help=argparse.SUPPRESS)
@@ -88,7 +88,6 @@ def settings_args(opts, args):
group_compat.add_argument("--ui-settings-file", type=str, help=argparse.SUPPRESS, default=os.path.join(data_path, 'config.json'))
group_compat.add_argument("--ui-config-file", type=str, help=argparse.SUPPRESS, default=os.path.join(data_path, 'ui-config.json'))
group_compat.add_argument("--hide-ui-dir-config", action='store_true', help=argparse.SUPPRESS, default=False)
group_compat.add_argument("--theme", type=str, help=argparse.SUPPRESS, default=None)
group_compat.add_argument("--disable-console-progressbars", action='store_true', help=argparse.SUPPRESS, default=True)
group_compat.add_argument("--disable-safe-unpickle", action='store_true', help=argparse.SUPPRESS, default=True)
group_compat.add_argument("--lowram", action='store_true', help=argparse.SUPPRESS)
+2
View File
@@ -363,6 +363,8 @@ def temp_disable_extensions():
theme_name = modules.shared.cmd_opts.theme
else:
theme_name = f'{modules.shared.opts.theme_type.lower()}/{modules.shared.opts.gradio_theme}'
if modules.shared.cmd_opts.locale is not None:
modules.shared.opts.ui_locale = modules.shared.cmd_opts.locale
if theme_name == 'lobe':
disable_themes.remove('sd-webui-lobe-theme')
+1 -1
Submodule wiki updated: 1c63a5f303...bcf135aad6