Add RTL languages support and improved Arabic localization

This commit is contained in:
xmodar
2022-10-24 19:03:01 +03:00
committed by AUTOMATIC1111
parent df0a1f8381
commit ca2ebc89c2
6 changed files with 551 additions and 691 deletions

View File

@@ -107,7 +107,7 @@ function processNode(node){
}
function dumpTranslations(){
dumped = {}
dumped = { rtl: localization.rtl || false }
Object.keys(original_lines).forEach(function(text){
if(dumped[text] !== undefined) return
@@ -129,6 +129,24 @@ onUiUpdate(function(m){
document.addEventListener("DOMContentLoaded", function() {
processNode(gradioApp())
if (localization.rtl) { // if the language is from right to left,
(new MutationObserver((mutations, observer) => { // wait for the style to load
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.tagName === 'STYLE') {
observer.disconnect();
for (const x of node.sheet.rules) { // find all rtl media rules
if (Array.from(x.media || []).includes('rtl')) {
x.media.appendMedium('all'); // enable them
}
}
}
})
});
})).observe(gradioApp(), { childList: true });
}
})
function download_localization() {