mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
I18N
I18N
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
localization_root = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'language')
|
||||
|
||||
|
||||
def localization_js(filename):
|
||||
data = {}
|
||||
|
||||
if isinstance(filename, str):
|
||||
full_name = os.path.abspath(os.path.join(localization_root, filename + '.json'))
|
||||
if os.path.exists(full_name):
|
||||
try:
|
||||
with open(full_name, encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
assert isinstance(data, dict)
|
||||
for k, v in data.items():
|
||||
assert isinstance(k, str)
|
||||
assert isinstance(v, str)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
print(f'Failed to load localization file {full_name}')
|
||||
|
||||
return f"window.localization = {json.dumps(data)}"
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
import os
|
||||
import gradio as gr
|
||||
import args_manager
|
||||
|
||||
from modules.localization import localization_js
|
||||
|
||||
|
||||
GradioTemplateResponseOriginal = gr.routes.templates.TemplateResponse
|
||||
|
||||
@@ -21,8 +25,11 @@ def webpath(fn):
|
||||
def javascript_html():
|
||||
script_js_path = webpath('javascript/script.js')
|
||||
context_menus_js_path = webpath('javascript/contextMenus.js')
|
||||
head = f'<script type="text/javascript" src="{script_js_path}"></script>\n'
|
||||
localization_js_path = webpath('javascript/localization.js')
|
||||
head = f'<script type="text/javascript">{localization_js(args_manager.args.language)}</script>\n'
|
||||
head += f'<script type="text/javascript" src="{script_js_path}"></script>\n'
|
||||
head += f'<script type="text/javascript" src="{context_menus_js_path}"></script>\n'
|
||||
head += f'<script type="text/javascript" src="{localization_js_path}"></script>\n'
|
||||
return head
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user