forked from bmaltais/kohya_ss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalization_ext.py
33 lines (23 loc) · 1.02 KB
/
localization_ext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import gradio as gr
import localization
def file_path(fn):
return f'file={os.path.abspath(fn)}?{os.path.getmtime(fn)}'
def js_html_str(language):
head = f'<script type="text/javascript">{localization.load_language_js(language)}</script>\n'
head += f'<script type="text/javascript" src="{file_path("js/script.js")}"></script>\n'
head += f'<script type="text/javascript" src="{file_path("js/localization.js")}"></script>\n'
return head
def add_javascript(language):
if language is None:
print('no language')
return
jsStr = js_html_str(language)
def template_response(*args, **kwargs):
res = localization.GrRoutesTemplateResponse(*args, **kwargs)
res.body = res.body.replace(b'</head>', f'{jsStr}</head>'.encode("utf8"))
res.init_headers()
return res
gr.routes.templates.TemplateResponse = template_response
if not hasattr(localization, 'GrRoutesTemplateResponse'):
localization.GrRoutesTemplateResponse = gr.routes.templates.TemplateResponse