make it possible to localize tooltips and placeholders

This commit is contained in:
AUTOMATIC1111 2023-08-22 12:00:29 +03:00
parent f6c52f4f41
commit 9e4019c5ff

View File

@ -107,12 +107,46 @@ function processNode(node) {
});
}
function localizeWholePage(){
processNode(gradioApp());
function elem(comp) {
if(comp.props.elem_id) {
elem_id = comp.props.elem_id;
} else{
elem_id = "component-" + comp.id;
}
return gradioApp().getElementById(elem_id);
}
for(comp of window.gradio_config.components) {
if(comp.props.webui_tooltip) {
var e = elem(comp);
var tl = e ? getTranslation(e.title) : undefined;
if (tl !== undefined) {
e.title = tl;
}
}
if(comp.props.placeholder) {
var e = elem(comp);
var textbox = e ? e.querySelector('[placeholder]') : null;
var tl = textbox ? getTranslation(textbox.placeholder) : undefined;
if (tl !== undefined) {
textbox.placeholder = tl;
}
}
}
}
function dumpTranslations() {
if (!hasLocalization()) {
// If we don't have any localization,
// we will not have traversed the app to find
// original_lines, so do that now.
processNode(gradioApp());
localizeWholePage();
}
var dumped = {};
if (localization.rtl) {
@ -154,7 +188,7 @@ document.addEventListener("DOMContentLoaded", function() {
});
});
processNode(gradioApp());
localizeWholePage();
if (localization.rtl) { // if the language is from right to left,
(new MutationObserver((mutations, observer) => { // wait for the style to load