Fixed language detection
This commit is contained in:
parent
f2e6f9ff71
commit
d719ee6a07
1 changed files with 25 additions and 8 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue