mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #3743 from hadicharara/hadicharara/added-support-for-rtl-layouts
Add Initial support for RTL layouts
This commit is contained in:
commit
84c007fa0b
82 changed files with 1163 additions and 242 deletions
|
@ -84,7 +84,7 @@ import globalize from './globalize';
|
|||
hours = Math.floor(hours);
|
||||
|
||||
if (hours) {
|
||||
parts.push(hours);
|
||||
parts.push(hours.toLocaleString(globalize.getCurrentDateTimeLocale()));
|
||||
}
|
||||
|
||||
ticks -= (hours * ticksPerHour);
|
||||
|
@ -95,7 +95,9 @@ import globalize from './globalize';
|
|||
ticks -= (minutes * ticksPerMinute);
|
||||
|
||||
if (minutes < 10 && hours) {
|
||||
minutes = '0' + minutes;
|
||||
minutes = (0).toLocaleString(globalize.getCurrentDateTimeLocale()) + minutes.toLocaleString(globalize.getCurrentDateTimeLocale());
|
||||
} else {
|
||||
minutes = minutes.toLocaleString(globalize.getCurrentDateTimeLocale());
|
||||
}
|
||||
parts.push(minutes);
|
||||
|
||||
|
@ -103,7 +105,9 @@ import globalize from './globalize';
|
|||
seconds = Math.floor(seconds);
|
||||
|
||||
if (seconds < 10) {
|
||||
seconds = '0' + seconds;
|
||||
seconds = (0).toLocaleString(globalize.getCurrentDateTimeLocale()) + seconds.toLocaleString(globalize.getCurrentDateTimeLocale());
|
||||
} else {
|
||||
seconds = seconds.toLocaleString(globalize.getCurrentDateTimeLocale());
|
||||
}
|
||||
parts.push(seconds);
|
||||
|
||||
|
|
|
@ -3,13 +3,20 @@ import isEmpty from 'lodash-es/isEmpty';
|
|||
import { currentSettings as userSettings } from './settings/userSettings';
|
||||
import Events from '../utils/events.ts';
|
||||
|
||||
const Direction = {
|
||||
rtl: 'rtl',
|
||||
ltr: 'ltr'
|
||||
};
|
||||
|
||||
/* eslint-disable indent */
|
||||
|
||||
const fallbackCulture = 'en-us';
|
||||
const RTL_LANGS = ['ar', 'fa', 'ur', 'he'];
|
||||
|
||||
const allTranslations = {};
|
||||
let currentCulture;
|
||||
let currentDateTimeCulture;
|
||||
let isRTL = false;
|
||||
|
||||
export function getCurrentLocale() {
|
||||
return currentCulture;
|
||||
|
@ -38,6 +45,37 @@ import Events from '../utils/events.ts';
|
|||
return fallbackCulture;
|
||||
}
|
||||
|
||||
export function getIsRTL() {
|
||||
return isRTL;
|
||||
}
|
||||
|
||||
function checkAndProcessDir(culture) {
|
||||
isRTL = false;
|
||||
console.log(culture);
|
||||
for (const lang of RTL_LANGS) {
|
||||
if (culture.includes(lang)) {
|
||||
isRTL = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setDocumentDirection(isRTL ? Direction.rtl : Direction.ltr);
|
||||
}
|
||||
|
||||
function setDocumentDirection(direction) {
|
||||
document.getElementsByTagName('body')[0].setAttribute('dir', direction);
|
||||
document.getElementsByTagName('html')[0].setAttribute('dir', direction);
|
||||
if (direction === Direction.rtl)
|
||||
import('../styles/rtl.scss');
|
||||
}
|
||||
|
||||
export function getIsElementRTL(element) {
|
||||
if (window.getComputedStyle) { // all browsers
|
||||
return window.getComputedStyle(element, null).getPropertyValue('direction') == 'rtl';
|
||||
}
|
||||
return element.currentStyle.direction == 'rtl';
|
||||
}
|
||||
|
||||
export function updateCurrentCulture() {
|
||||
let culture;
|
||||
try {
|
||||
|
@ -46,6 +84,7 @@ import Events from '../utils/events.ts';
|
|||
console.error('no language set in user settings');
|
||||
}
|
||||
culture = culture || getDefaultLanguage();
|
||||
checkAndProcessDir(culture);
|
||||
|
||||
currentCulture = normalizeLocaleName(culture);
|
||||
|
||||
|
@ -200,7 +239,7 @@ import Events from '../utils/events.ts';
|
|||
export function translate(key) {
|
||||
let val = translateKey(key);
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
val = replaceAll(val, '{' + (i - 1) + '}', arguments[i]);
|
||||
val = replaceAll(val, '{' + (i - 1) + '}', arguments[i].toLocaleString(currentCulture));
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
@ -257,7 +296,9 @@ export default {
|
|||
getCurrentLocale,
|
||||
getCurrentDateTimeLocale,
|
||||
register,
|
||||
updateCurrentCulture
|
||||
updateCurrentCulture,
|
||||
getIsRTL,
|
||||
getIsElementRTL
|
||||
};
|
||||
|
||||
/* eslint-enable indent */
|
||||
|
|
|
@ -88,7 +88,7 @@ export function getQueryPagingHtml (options) {
|
|||
|
||||
if (showControls) {
|
||||
html += '<span style="vertical-align:middle;">';
|
||||
html += globalize.translate('ListPaging', (totalRecordCount ? startIndex + 1 : 0), recordsEnd, totalRecordCount);
|
||||
html += globalize.translate('ListPaging', totalRecordCount ? startIndex + 1 : 0, recordsEnd, totalRecordCount);
|
||||
html += '</span>';
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue