Skip to content

Commit 2f4ad70

Browse files
Initial RTL support for Farsi localisation (#3350)
Co-authored-by: Sepideh Adamiat <12543653+sepideh-adamiat@users.noreply.github.com>
1 parent 329b591 commit 2f4ad70

File tree

12 files changed

+46
-30
lines changed

12 files changed

+46
-30
lines changed

frontend/common/lang.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ export const getCurrentLanguage = () => {
125125
return getLanguage(to_search)
126126
}
127127

128+
export const getWritingDirection = () => {
129+
return t("t_language_direction") === "rtl" ? "rtl" : "ltr"
130+
}
128131
const getLanguage = _.memoize((to_search) => {
129132
for (const lang of to_search) {
130133
if (lang != null) {

frontend/components/CellOutput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export let RawHTMLContainer = ({ body, className = "", persist_js_state = false,
612612
}
613613
}, [body, last_run_timestamp, pluto_actions, sanitize_html])
614614

615-
return html`<div class="raw-html-wrapper ${className}" ref=${container_ref}></div>`
615+
return html`<div dir="auto" class="raw-html-wrapper ${className}" ref=${container_ref}></div>`
616616
}
617617

618618
// https://github.com/fonsp/Pluto.jl/issues/1692

frontend/components/Editor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { open_pluto_popup } from "../common/open_pluto_popup.js"
4848
import { get_included_external_source } from "../common/external_source.js"
4949
import { ProjectTomlEditor } from "./ProjectTomlEditor.js"
5050
import { LanguagePicker } from "./LanguagePicker.js"
51-
import { getCurrentLanguage, t, th } from "../common/lang.js"
51+
import { getCurrentLanguage, getWritingDirection, t, th } from "../common/lang.js"
5252
import { PlutoLandUpload } from "./PlutoLandUpload.js"
5353
import { BigPkgTerminal } from "./PkgTerminalView.js"
5454
import { is_desktop, move_notebook, wait_for_file_move } from "./DesktopInterface.js"
@@ -1470,6 +1470,7 @@ ${t("t_key_autosave_description")}`
14701470
updateLang() {
14711471
const lang = this.state.notebook.metadata?.frontmatter?.language
14721472
document.documentElement.lang = lang ?? getCurrentLanguage()
1473+
document.documentElement.dir = getWritingDirection()
14731474
}
14741475

14751476
componentDidMount() {

frontend/components/Logs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,5 @@ const LogViewAnsiUp = (/** @type {{value: string}} */ { value }) => {
179179
node_ref.current.innerHTML = ansi_to_html(value)
180180
}, [node_ref.current, value])
181181

182-
return html`<pre ref=${node_ref}></pre>`
182+
return html`<pre dir="auto" ref=${node_ref}></pre>`
183183
}

frontend/components/PkgTerminalView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const TerminalViewAnsiUp = ({ value, hide_button = false }) => {
3131
></button>`
3232

3333
return !!value
34-
? html`<pkg-terminal
34+
? html`<pkg-terminal dir="ltr"
3535
>${button}
3636
<div class="scroller" tabindex="0"><pre ref=${node_ref} class="pkg-terminal"></pre></div
3737
></pkg-terminal>`

frontend/components/welcome/Open.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const Open = ({ client, connected, CustomPicker, show_samples, on_start_n
4141

4242
return html`<${PasteHandler} on_start_navigation=${on_start_navigation} />
4343
<h2>${picker.text}</h2>
44-
<div id="new" class=${is_desktop() ? "desktop_opener" : ""}>
44+
<div id="new" dir="ltr" class=${is_desktop() ? "desktop_opener" : ""}>
4545
${is_desktop()
4646
? html`
4747
<div class="desktop_picker_group">

frontend/components/welcome/Welcome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const Welcome = ({ launch_params }) => {
171171
/>
172172
</div>
173173
</section>
174-
<section id="featured">
174+
<section id="featured" dir="ltr">
175175
<div>
176176
<${Featured} sources=${featured_sources} direct_html_links=${launch_params.featured_direct_html_links} />
177177
</div>

frontend/editor.css

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pluto-editor {
7676
min-width: 0;
7777
container-type: inline-size;
7878
container-name: editor;
79+
overflow-x: clip;
7980
}
8081

8182
main {
@@ -106,6 +107,7 @@ pluto-editor main {
106107
/* Second part: push away from the right to take up all free space */ min((100% - (700px + 25px + 6px)), /* but don't do this more than */ 500px)
107108
);
108109
position: relative;
110+
margin-left: auto;
109111
}
110112

111113
pluto-notebook {
@@ -632,7 +634,7 @@ dialog#export div#container {
632634
flex-direction: row;
633635
display: flex;
634636
max-width: 1000px;
635-
padding-right: 10em;
637+
padding-inline-end: 10em;
636638
margin: 0 auto;
637639
position: relative;
638640
height: var(--header-height);
@@ -693,7 +695,7 @@ dialog#export .export_small_btns {
693695
padding: 0.9em;
694696
border-radius: 0.9em;
695697
position: absolute;
696-
right: 0.8em;
698+
inset-inline-end: 0.8em;
697699
top: 0em;
698700
background: var(--export-bg-color);
699701
}
@@ -953,9 +955,9 @@ div.desktop_picker_group span {
953955
color: var(--nav-filepicker-color);
954956
border: 2px solid var(--footer-input-border-color);
955957
border-radius: 3px;
956-
border-right: none;
957-
border-top-right-radius: 0;
958-
border-bottom-right-radius: 0;
958+
border-inline-end: none;
959+
border-end-end-radius: 0;
960+
border-start-end-radius: 0;
959961
}
960962

961963
pluto-filepicker .cm-scroller {
@@ -1088,7 +1090,7 @@ nav#at_the_top:after {
10881090
nav#at_the_top > pluto-filepicker .cm-editor,
10891091
nav#at_the_top > div.desktop_picker_group span {
10901092
border: 2px solid transparent;
1091-
border-right: none;
1093+
border-inline-end: none;
10921094
transition: border 0.15s ease-in-out;
10931095
}
10941096
nav#at_the_top > pluto-filepicker button,
@@ -1101,7 +1103,7 @@ nav#at_the_top:after {
11011103
header:hover > nav#at_the_top > div.desktop_picker_group span,
11021104
header:focus-within > nav#at_the_top > div.desktop_picker_group span {
11031105
border: 2px solid var(--footer-input-border-color);
1104-
border-right: none;
1106+
border-inline-end: none;
11051107
}
11061108
header:hover > nav#at_the_top > pluto-filepicker button,
11071109
header:focus-within > nav#at_the_top > pluto-filepicker button,
@@ -1643,6 +1645,7 @@ pluto-input .cm-editor {
16431645
/* Make sure that scrolling an editor into view gives some breathing room */
16441646
scroll-margin-block: 20vh;
16451647
min-height: 25px;
1648+
direction: ltr;
16461649
}
16471650
pluto-input:focus-within .cm-editor {
16481651
/* z-index increased by 1 to make sure that the autocomplete window shows above all other editors, see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context */
@@ -1708,7 +1711,6 @@ pluto-shoulder {
17081711
--invisible-border: calc(0.5 * var(--pluto-cell-spacing));
17091712
--shoulder-width: calc(28px + var(--invisible-border));
17101713
--border-radius: calc(5px + var(--invisible-border));
1711-
17121714
left: calc(0px - var(--shoulder-width));
17131715
width: var(--shoulder-width);
17141716
border-radius: var(--border-radius) 0px 0px var(--border-radius);
@@ -1722,6 +1724,7 @@ pluto-shoulder {
17221724
bottom: calc(0px - var(--invisible-border));
17231725
border: var(--invisible-border) solid rgba(0, 0, 0, 0);
17241726
border-right: none;
1727+
direction: ltr;
17251728
}
17261729
pluto-editor.fullscreen pluto-shoulder {
17271730
--shoulder-width: 2000px;
@@ -2103,9 +2106,8 @@ pluto-input > .input_context_menu li button {
21032106
margin-top: 1px;
21042107
background-size: var(--size) var(--size);
21052108
background-position: center;
2106-
margin-right: calc(var(--size) / 3);
2109+
margin-inline-end: calc(var(--size) / 3);
21072110
}
2108-
21092111
.ctx_icon {
21102112
filter: var(--image-filters);
21112113
}
@@ -2748,7 +2750,7 @@ pluto-helpbox > header > button.helpbox-tab-key > .tabicon {
27482750
background-size: var(--size);
27492751
margin-bottom: calc(-0.15 * var(--size));
27502752
filter: var(--image-filters);
2751-
margin-right: 0.6em;
2753+
margin-inline-end: 0.6em;
27522754
display: inline-block;
27532755
}
27542756
pluto-helpbox > header > button.helpbox-docs > .tabicon {
@@ -2901,7 +2903,7 @@ button.helpbox-tab-key {
29012903
}
29022904

29032905
button.helpbox-tab-key.helpbox-process {
2904-
margin-right: auto;
2906+
margin-inline-end: auto;
29052907
}
29062908

29072909
button.helpbox-process.busy {
@@ -3309,7 +3311,7 @@ footer form > label {
33093311
}
33103312

33113313
footer form > label {
3312-
margin-right: 1em;
3314+
margin-inline-end: 1em;
33133315
flex: 0 1 auto;
33143316
overflow: hidden;
33153317
text-overflow: ellipsis;
@@ -3339,17 +3341,21 @@ footer input {
33393341
background: var(--white);
33403342
font-family: inherit;
33413343
font-size: inherit;
3342-
border-radius: 3px 0 0 3px;
3344+
border-radius: 3px;
3345+
border-end-end-radius: 0;
3346+
border-start-end-radius: 0;
33433347
padding: 3px;
3344-
border-right: none;
3348+
border-inline-end: none;
33453349
}
33463350

33473351
header#pluto-nav pluto-filepicker button,
33483352
header#pluto-nav .desktop_picker_group button,
33493353
footer button {
33503354
margin: 0px;
33513355
background: var(--footer-filepicker-focus-color);
3352-
border-radius: 0 3px 3px 0;
3356+
border-radius: 3px;
3357+
border-start-start-radius: 0;
3358+
border-end-start-radius: 0;
33533359
border: 3px solid var(--footer-filepicker-focus-color);
33543360
color: var(--footer-filepicker-button-color);
33553361
/* border: none; */
@@ -3378,7 +3384,7 @@ footer #info {
33783384
display: flex;
33793385
align-items: center;
33803386
gap: 0.5rem;
3381-
margin-right: 1rem;
3387+
margin-inline-end: 1rem;
33823388
font-size: 0.75rem;
33833389
flex: 0 2 auto;
33843390
}

frontend/index.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ p {
5353
}
5454

5555
ul {
56-
padding-left: 0;
56+
padding-inline-start: 0;
5757
list-style: none;
5858
}
5959

@@ -105,9 +105,9 @@ pluto-filepicker .cm-editor {
105105
color: var(--nav-filepicker-color);
106106
border: 2px solid var(--footer-filepicker-focus-color);
107107
border-radius: 3px;
108-
border-right: none;
109-
border-top-right-radius: 0;
110-
border-bottom-right-radius: 0;
108+
border-inline-end: none;
109+
border-end-end-radius: 0;
110+
border-start-end-radius: 0;
111111
flex: 1 1 auto;
112112
width: 0px;
113113
/* min-width: 0px; */
@@ -155,8 +155,8 @@ pluto-filepicker button,
155155

156156
#new pluto-filepicker button {
157157
cursor: pointer;
158-
border-top-left-radius: 0;
159-
border-bottom-left-radius: 0;
158+
border-start-start-radius: 0;
159+
border-end-start-radius: 0;
160160
flex: 0 1 auto;
161161
}
162162

@@ -261,7 +261,7 @@ body.nosessions ul#new ~ * {
261261

262262
#recent button {
263263
margin: 0px;
264-
margin-right: 0.2em;
264+
margin-inline-end: 0.2em;
265265
padding: 1px;
266266
opacity: 0.6;
267267
border: none;

frontend/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { html, render } from "./imports/Preact.js"
22
import "./common/NodejsCompatibilityPolyfill.js"
33

44
import { Welcome } from "./components/welcome/Welcome.js"
5+
import { getCurrentLanguage, getWritingDirection } from "./common/lang.js"
56

67
const url_params = new URLSearchParams(window.location.search)
78

@@ -29,5 +30,8 @@ const launch_params = {
2930

3031
console.log("Launch parameters: ", launch_params)
3132

33+
document.documentElement.lang = getCurrentLanguage()
34+
document.documentElement.dir = getWritingDirection()
35+
3236
// @ts-ignore
3337
render(html`<${Welcome} launch_params=${launch_params} />`, document.querySelector("#app"))

0 commit comments

Comments
 (0)