From 9e4019c5ffb3c105156c6c8a9af83fde52d7f0c4 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Tue, 22 Aug 2023 12:00:29 +0300 Subject: [PATCH] make it possible to localize tooltips and placeholders --- javascript/localization.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/javascript/localization.js b/javascript/localization.js index 0c9032f9b..26f21bcf2 100644 --- a/javascript/localization.js +++ b/javascript/localization.js @@ -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