Make localization.js do nothing if there's no localization to do
This commit is contained in:
parent
335428c2c8
commit
16f0739db0
@ -25,6 +25,10 @@ re_emoji = /[\p{Extended_Pictographic}\u{1F3FB}-\u{1F3FF}\u{1F9B0}-\u{1F9B3}]/u
|
|||||||
original_lines = {}
|
original_lines = {}
|
||||||
translated_lines = {}
|
translated_lines = {}
|
||||||
|
|
||||||
|
function hasLocalization() {
|
||||||
|
return window.localization && Object.keys(window.localization).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
function textNodesUnder(el){
|
function textNodesUnder(el){
|
||||||
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
|
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
|
||||||
while(n=walk.nextNode()) a.push(n);
|
while(n=walk.nextNode()) a.push(n);
|
||||||
@ -119,6 +123,21 @@ function dumpTranslations(){
|
|||||||
return dumped
|
return dumped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function download_localization() {
|
||||||
|
var text = JSON.stringify(dumpTranslations(), null, 4)
|
||||||
|
|
||||||
|
var element = document.createElement('a');
|
||||||
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||||
|
element.setAttribute('download', "localization.json");
|
||||||
|
element.style.display = 'none';
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
element.click();
|
||||||
|
|
||||||
|
document.body.removeChild(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hasLocalization()) {
|
||||||
onUiUpdate(function (m) {
|
onUiUpdate(function (m) {
|
||||||
m.forEach(function (mutation) {
|
m.forEach(function (mutation) {
|
||||||
mutation.addedNodes.forEach(function (node) {
|
mutation.addedNodes.forEach(function (node) {
|
||||||
@ -149,17 +168,4 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
})).observe(gradioApp(), { childList: true });
|
})).observe(gradioApp(), { childList: true });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function download_localization() {
|
|
||||||
var text = JSON.stringify(dumpTranslations(), null, 4)
|
|
||||||
|
|
||||||
var element = document.createElement('a');
|
|
||||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
|
||||||
element.setAttribute('download', "localization.json");
|
|
||||||
element.style.display = 'none';
|
|
||||||
document.body.appendChild(element);
|
|
||||||
|
|
||||||
element.click();
|
|
||||||
|
|
||||||
document.body.removeChild(element);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user