Commit 9e4019c5 authored by AUTOMATIC1111's avatar AUTOMATIC1111
Browse files

make it possible to localize tooltips and placeholders

parent f6c52f4f
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
@@ -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