From d719ee6a07fba8ff6e7fedac8af440812aeaae7e Mon Sep 17 00:00:00 2001 From: Hadi Charara Date: Fri, 8 Jul 2022 12:41:58 -0400 Subject: [PATCH] Fixed language detection --- src/scripts/globalize.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/scripts/globalize.js b/src/scripts/globalize.js index 5e1122a9c5..f7da47d8e8 100644 --- a/src/scripts/globalize.js +++ b/src/scripts/globalize.js @@ -6,6 +6,7 @@ import { currentSettings as userSettings } from './settings/userSettings'; /* eslint-disable indent */ const fallbackCulture = 'en-us'; + const RTL_LANGS = ['ar', 'fa', 'ur', 'he']; const allTranslations = {}; let currentCulture; @@ -43,6 +44,29 @@ import { currentSettings as userSettings } from './settings/userSettings'; return isRTL; } + function checkAndProcessDir(culture) { + for (const lang of RTL_LANGS) { + if (culture.includes(lang)) { + isRTL = true; + break; + } + } + + if (isRTL) + processIsRTL(); + else + processIsLTR(); + } + + function processIsRTL() { + document.getElementsByTagName('body')[0].setAttribute('dir', 'rtl'); + import('../styles/rtl.scss'); + } + + function processIsLTR() { + document.getElementsByTagName('body')[0].setAttribute('dir', 'ltr'); + } + export function getElementIsRTL(element) { let elementIsRTL = false; if (window.getComputedStyle) { // all browsers @@ -61,14 +85,7 @@ import { currentSettings as userSettings } from './settings/userSettings'; console.error('no language set in user settings'); } culture = culture || getDefaultLanguage(); - isRTL = culture === 'ar' || culture === 'fa' || culture === 'ur_PK' || culture === 'he'; - - if (isRTL) { - document.getElementsByTagName('body')[0].setAttribute('dir', 'rtl'); - import('../styles/rtl.scss'); - } else { - document.getElementsByTagName('body')[0].setAttribute('dir', 'ltr'); - } + checkAndProcessDir(culture); currentCulture = normalizeLocaleName(culture);