From ca2ebc89c2d18c02d9e337b660fdabe7178a6ccc Mon Sep 17 00:00:00 2001 From: xmodar Date: Mon, 24 Oct 2022 19:03:01 +0300 Subject: Add RTL languages support and improved Arabic localization --- javascript/localization.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'javascript/localization.js') diff --git a/javascript/localization.js b/javascript/localization.js index e6644635..6fb2fccd 100644 --- a/javascript/localization.js +++ b/javascript/localization.js @@ -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() { -- cgit v1.2.3 From d3eef0aa0c773b8b9dc3a4f119e5709744e35af6 Mon Sep 17 00:00:00 2001 From: xmodar Date: Tue, 25 Oct 2022 06:55:17 +0300 Subject: Remove rtl: false from localizations --- javascript/localization.js | 5 ++++- localizations/ja_JP.json | 1 - localizations/ko_KR.json | 1 - localizations/ru_RU.json | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'javascript/localization.js') diff --git a/javascript/localization.js b/javascript/localization.js index 6fb2fccd..f92d2d24 100644 --- a/javascript/localization.js +++ b/javascript/localization.js @@ -107,7 +107,10 @@ function processNode(node){ } function dumpTranslations(){ - dumped = { rtl: localization.rtl || false } + dumped = {} + if (localization.rtl) { + dumped.rtl = true + } Object.keys(original_lines).forEach(function(text){ if(dumped[text] !== undefined) return diff --git a/localizations/ja_JP.json b/localizations/ja_JP.json index ae533e06..a6cc2477 100644 --- a/localizations/ja_JP.json +++ b/localizations/ja_JP.json @@ -1,5 +1,4 @@ { - "rtl": false, "⤡": "⤡", "⊞": "⊞", "×": "×", diff --git a/localizations/ko_KR.json b/localizations/ko_KR.json index 6daad1b7..ab12c37e 100644 --- a/localizations/ko_KR.json +++ b/localizations/ko_KR.json @@ -1,5 +1,4 @@ { - "rtl": false, "×": "×", "•": "•", "⊞": "⊞", diff --git a/localizations/ru_RU.json b/localizations/ru_RU.json index 8ec2c5a3..664d36ea 100644 --- a/localizations/ru_RU.json +++ b/localizations/ru_RU.json @@ -1,5 +1,4 @@ { - "rtl": false, "⤡": "⤡", "⊞": "⊞", "×": "×", -- cgit v1.2.3