Skip to content

Commit de34023

Browse files
authored
fix: use translation for aspect ratios label (#3001)
use javascript code instead of python handling for updates for lllyasviel/Fooocus#2590
1 parent 12dc239 commit de34023

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

javascript/localization.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ function refresh_style_localization() {
8080
processNode(document.querySelector('.style_selections'));
8181
}
8282

83+
function refresh_aspect_ratios_label(value) {
84+
label = document.querySelector('#aspect_ratios_accordion div span[data-original-text="Aspect Ratios"]')
85+
translation = getTranslation("Aspect Ratios")
86+
label.textContent = translation + " " + htmlDecode(value)
87+
}
88+
8389
function localizeWholePage() {
8490
processNode(gradioApp());
8591

javascript/script.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,8 @@ function set_theme(theme) {
256256
window.location.replace(gradioURL + '?__theme=' + theme);
257257
}
258258
}
259+
260+
function htmlDecode(input) {
261+
var doc = new DOMParser().parseFromString(input, "text/html");
262+
return doc.documentElement.textContent;
263+
}

webui.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,15 @@ def trigger_metadata_preview(filepath):
277277
choices=flags.Performance.list(),
278278
value=modules.config.default_performance,
279279
elem_classes=['performance_selection'])
280-
with gr.Accordion(label='Aspect Ratios', open=False) as aspect_ratios_accordion:
280+
with gr.Accordion(label='Aspect Ratios', open=False, elem_id='aspect_ratios_accordion') as aspect_ratios_accordion:
281281
aspect_ratios_selection = gr.Radio(label='Aspect Ratios', show_label=False,
282282
choices=modules.config.available_aspect_ratios_labels,
283283
value=modules.config.default_aspect_ratio,
284284
info='width × height',
285285
elem_classes='aspect_ratios')
286286

287-
def change_aspect_ratio(text):
288-
import re
289-
regex = re.compile('<.*?>')
290-
cleaned_text = re.sub(regex, '', text)
291-
return gr.update(label='Aspect Ratios ' + cleaned_text)
292-
293-
aspect_ratios_selection.change(change_aspect_ratio, inputs=aspect_ratios_selection, outputs=aspect_ratios_accordion, queue=False, show_progress=False)
294-
shared.gradio_root.load(change_aspect_ratio, inputs=aspect_ratios_selection, outputs=aspect_ratios_accordion, queue=False, show_progress=False)
287+
aspect_ratios_selection.change(lambda x: None, inputs=aspect_ratios_selection, queue=False, show_progress=False, _js='(x)=>{refresh_aspect_ratios_label(x);}')
288+
shared.gradio_root.load(lambda x: None, inputs=aspect_ratios_selection, queue=False, show_progress=False, _js='(x)=>{refresh_aspect_ratios_label(x);}')
295289

296290
image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number)
297291

0 commit comments

Comments
 (0)