refactor: Support vladmandic/automatic
parent
059f80e1f6
commit
89a0228050
|
|
@ -469,7 +469,7 @@
|
|||
let _count = 0
|
||||
|
||||
const observer = new MutationObserver(mutations => {
|
||||
if (Object.keys(localization).length) return; // disabled if original translation enabled
|
||||
if (window.localization && Object.keys(window.localization).length) return; // disabled if original translation enabled
|
||||
if (Object.keys(opts).length === 0) return; // does nothing if opts is not loaded
|
||||
|
||||
let _nodesCount = 0, _now = performance.now()
|
||||
|
|
|
|||
|
|
@ -1,16 +1,42 @@
|
|||
# This helper script loads the list of localization files and
|
||||
# exposes the current localization file name and path to the javascript side
|
||||
|
||||
import os
|
||||
import gradio as gr
|
||||
from pathlib import Path
|
||||
from modules import localization, script_callbacks, shared
|
||||
from modules import script_callbacks, shared
|
||||
import json
|
||||
|
||||
localizations = {}
|
||||
localizations_dir = shared.cmd_opts.localizations_dir if "localizations_dir" in shared.cmd_opts else "localizations"
|
||||
|
||||
def list_localizations(dirname):
|
||||
localizations.clear()
|
||||
|
||||
print("dirname: ", dirname)
|
||||
|
||||
for file in os.listdir(dirname):
|
||||
fn, ext = os.path.splitext(file)
|
||||
if ext.lower() != ".json":
|
||||
continue
|
||||
|
||||
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
|
||||
|
||||
print("localizations: ", localizations)
|
||||
|
||||
|
||||
list_localizations(localizations_dir)
|
||||
|
||||
# Webui root path
|
||||
ROOT_DIR = Path().absolute()
|
||||
|
||||
# The localization files
|
||||
I18N_DIRS = { k: str(Path(v).relative_to(ROOT_DIR).as_posix()) for k, v in localization.localizations.items() }
|
||||
I18N_DIRS = { k: str(Path(v).relative_to(ROOT_DIR).as_posix()) for k, v in localizations.items() }
|
||||
|
||||
# Register extension options
|
||||
def on_ui_settings():
|
||||
|
|
@ -22,7 +48,7 @@ def on_ui_settings():
|
|||
shared.opts.add_option("bilingual_localization_logger", shared.OptionInfo(False, "Enable Devtools Log", section=BL_SECTION))
|
||||
|
||||
# current localization file
|
||||
shared.opts.add_option("bilingual_localization_file", shared.OptionInfo("None", "Localization file (Please leave `User interface` - `Localization` as None)", gr.Dropdown, lambda: {"choices": ["None"] + list(localization.localizations.keys())}, refresh=lambda: localization.list_localizations(shared.cmd_opts.localizations_dir), section=BL_SECTION))
|
||||
shared.opts.add_option("bilingual_localization_file", shared.OptionInfo("None", "Localization file (Please leave `User interface` - `Localization` as None)", gr.Dropdown, lambda: {"choices": ["None"] + list(localizations.keys())}, refresh=lambda: list_localizations(localizations_dir), section=BL_SECTION))
|
||||
|
||||
# translation order
|
||||
shared.opts.add_option("bilingual_localization_order", shared.OptionInfo("Translation First", "Translation display order", gr.Radio, {"choices": ["Translation First", "Original First"]}, section=BL_SECTION))
|
||||
|
|
|
|||
Loading…
Reference in New Issue