Skip to content

Commit

Permalink
add locale override capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Feb 9, 2025
1 parent a34d331 commit d01fefd
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Change Log for SD.Next

## Update for 2025-02-08
## Update for 2025-02-09

- **Hints**
- added/updated 100+ ui hints!
- [hints](https://github.com/vladmandic/wiki/Hints) documentation and contribution guide
- **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`
Expand Down
2 changes: 2 additions & 0 deletions html/override_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
3 changes: 3 additions & 0 deletions html/override_hr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "id": "", "label": "Reprocess", "localized": "Ponovi", "hint": "Ponovno obradite prethodne generacije koristeći različite parametre" }
]
4 changes: 4 additions & 0 deletions html/override_ko.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "id": "", "label": "🎲️", "localized": "", "hint": "무작위 시드 사용" },
{ "id": "", "label": "🔄", "localized": "", "hint": "초기화" }
]
27 changes: 20 additions & 7 deletions javascript/setHints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions modules/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def handle_exception(req: Request, e: Exception):
}
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}")

Expand Down
3 changes: 1 addition & 2 deletions modules/cmd_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from 1c63a5 to bcf135

0 comments on commit d01fefd

Please sign in to comment.