Skip to content

Commit

Permalink
Support RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 10, 2025
1 parent 51a349d commit 73ccf92
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion submodules/webextensions-lib-l10n
2 changes: 1 addition & 1 deletion submodules/webextensions-lib-menu-ui
2 changes: 1 addition & 1 deletion submodules/webextensions-lib-tab-favicon-helper
22 changes: 22 additions & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,25 @@ export async function getTSTVersion() {
}
return '0.0';
}

const RTL_LANGUAGES = new Set([
'ar',
'he',
'fa',
'ur',
'ps',
'sd',
'ckb',
'prs',
'rhg',
]);

export function isRTL() {
const lang = (
navigator.language ||
navigator.userLanguage ||
//(new Intl.DateTimeFormat()).resolvedOptions().locale ||
''
).split('-')[0];
return RTL_LANGUAGES.has(lang);
}
4 changes: 3 additions & 1 deletion webextensions/options/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import {
log,
configs
configs,
isRTL,
} from '/common/common.js';
import * as Permissions from '/common/permissions.js';
import Options from '/extlib/Options.js';
Expand Down Expand Up @@ -37,6 +38,7 @@ window.addEventListener('DOMContentLoaded', async () => {
for (const label of document.querySelectorAll('#menu-items label, #bookmarksPermissionCheck')) {
label.lastChild.nodeValue = label.lastChild.nodeValue.replace(/\(&[a-z]\)|&([a-z])/i, '$1');
}
document.documentElement.classList.toggle('rtl', isRTL());

await configs.$loaded;

Expand Down
4 changes: 4 additions & 0 deletions webextensions/options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
opacity: 0;
}

:root.rtl {
direction: rtl;
}

body {
background: var(--bg-color);
color: var(--text-color);
Expand Down
13 changes: 9 additions & 4 deletions webextensions/panel/panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
}
}

:root.rtl {
direction: rtl;
}

body {
background: var(--bg-color);
color: var(--text-color);
Expand Down Expand Up @@ -109,14 +113,15 @@ body {
}

#tabs li .checkbox-container {
margin-left: 0.5em;
margin-inline-start: 0.5em;
padding: var(--item-vertical-padding) 0;
}

#tabs li label {
flex-grow: 1;
overflow: hidden;
padding: var(--item-vertical-padding) 1em var(--item-vertical-padding) 0;
padding-block: var(--item-vertical-padding);
padding-inline: 0 1em;
text-overflow: ellipsis;
white-space: nowrap;
}
Expand Down Expand Up @@ -212,11 +217,11 @@ body {
bottom: 0;
color: var(--text-color);
display: none;
left: 0;
inset-inline-start: 0;
inset-inline-end: 0;
line-height: 1.5;
padding: 1.5em;
position: fixed;
right: 0;
text-shadow: 0 0 0.5em var(--bg-color),
0 0 0.5em var(--bg-color),
0 0 0.5em var(--bg-color),
Expand Down
3 changes: 3 additions & 0 deletions webextensions/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
shouldIncludeHidden,
handleMissingReceiverError,
callTSTAPI,
isRTL,
} from '/common/common.js';
import * as Constants from '/common/constants.js';
import DragSelection from '/common/drag-selection.js';
Expand All @@ -37,6 +38,8 @@ const gTabItems = new Map();
const gHighlightedTabs = new Map();

window.addEventListener('DOMContentLoaded', async () => {
document.documentElement.classList.toggle('rtl', isRTL());

gTabBar = document.querySelector('#tabs');
gMenu = document.querySelector('#menu');
gMenu.ui = new MenuUI({
Expand Down

0 comments on commit 73ccf92

Please sign in to comment.