Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right to left writting is now possible #946

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ discord_id: # your discord id (18-digit unique numerical identifier)
contact_note: >
You can even add a little note about which of these is the best way to reach you.


# -----------------------------------------------------------------------------
# Right-to-left scripts
# -----------------------------------------------------------------------------
rtl_langs: ["ar","arc","az","dv","he","ku","fa","ur"]

# -----------------------------------------------------------------------------
# Analytics and search engine verification
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -222,7 +228,7 @@ jekyll-archives:
tag: '/blog/tag/:name/'
category: '/blog/category/:name/'

display_tags: ['formatting', 'images', 'links', 'math', 'code'] # this tags will be dispalyed on the front page of your blog
display_tags: ['formatting', 'images', 'links', 'math', 'code', 'internationalization'] # this tags will be dispalyed on the front page of your blog

# -----------------------------------------------------------------------------
# Jekyll Scholar
Expand Down
3 changes: 2 additions & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
{%- include header.html %}

<!-- Content -->
<div class="container mt-5">
<div class="container mt-5" {% if site.rtl_langs contains page.lang %}dir="rtl" align="right"{% endif %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's also worth adding "rtl" class to this div, so that we can conditionally change CSS of some inner elements (eg, the border location of the blockquote).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy that you find it useful :) . I have to clarify one important fact: I'm by no means dominant on HTML, SCSS, and I'm afraid, even after going through Jekyll's documentation several times, I haven't fully comprehend its philosophy. So please take my response with a grain of salt, i.e., modify it as you feel it's better.

Coming back to your comment, I actually don't know how to add it to div here. If you provide me with some hints, I would be happy to work on it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Thanks for this great idea.

It is a common practice (+) to add dir=rtl in a separate div. So, maybe it is better to add it like this:

<div {% if site.rtl_langs contains page.lang %} dir="rtl" endif %>
Stuff
</div>

Also, I see that you have added align=right. Why do you think that is necessary? I haven't seen it anywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I was not aware of this practice, but it seems to work on my local machine.

align=right is to decouple the text of each post from the body of the page which have some use cases. E.g., one might want to have the header and navigation in, say English, but the posts in a rtl script. An example post is here.

>
{{ content }}
</div>

Expand Down
74 changes: 74 additions & 0 deletions _posts/2022-10-15-rtl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
layout: post
title: Right to left scripting
date: 2022-10-15
description: you can also write from right to left
lang: fa
tags: internationalization formatting math code
category: internationalization
---

# عنوان
این یک پست نمونه برای سنجش نوشتارهای راست‌به‌چپ است.


## فرمول‌نویسی
فرمول‌ها هم مانند کد به درستی به نمایش در‌خواهند آمد:


$$
\sum_{k=1}^\infty |\langle x, e_k \rangle|^2 \leq \|x\|^2
$$

## کد
کدها هم‌چنان مانند قبل از چپ‌به‌راست خواهند بود.

```python
if lang=="rtl"
print("I am a right-to-left script!")
```
arashgmn marked this conversation as resolved.
Show resolved Hide resolved

## بلاک
بلاک‌ها همواره چپ‌چین خواهند ماند:

---
layout: page
title: project
description: a project with a background image
img: /assets/img/12.jpg
---
arashgmn marked this conversation as resolved.
Show resolved Hide resolved

حتی اگر به زبان‌های راست‌به‌چپ نوشته شوند:

---
صفحه‌بندی: صفحه
عنوان: پروژه
توضیحات: یک پروژه با تصویر زمینه
---

## نقل‌قول
> نقل‌قول‌ها به این شکل به نمایش درخواهند آمد.
arashgmn marked this conversation as resolved.
Show resolved Hide resolved

زیباتر خواهد بود اگر خط عمودی به راست انتقال داده شود. این کار با ویرایش _base.scss امکان‌پذیر است:

```scss
blockquote {
background: var(--global-bg-color);
border-left: 2px solid var(--global-theme-color); // change to border-right:
margin: 1.5em 10px;
padding: 0.5em 10px;
font-size: 1.2rem;
}

...


.post-content{
blockquote {
border-left: 5px solid var(--global-theme-color); // change to border-right: ...
padding: 8px;
}
}
```
Comment on lines +54 to +72
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of providing a suggestion on how to update CSS here, it's better the add rtl-conditional style overrides directly to _scss/_base.scss, like this (I haven't tested the code below, so please adjust as necessary):

rtl blockquote {
    border-left: none;
    border-right: 2px solid var(--global-theme-color);
}
.post-content {
    rtl blockquote {
        border-left: none;
        border-right: 2px solid var(--global-theme-color);
    }
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check this locally, and push a new commit if it worked on my side.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review my new commit (lines 71-74 and 971-977).


منطقا باید بتوان با توجه به جهت‌گیری متن (rtl یا ltr) صفت مناسب را تعریف کرد. اما من چندان به sass مسلط نیستم. امیدوارم فرد مسلط‌تری این مشکل کوچک را رفع کند.
2 changes: 2 additions & 0 deletions _sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ pre {
background-color: var(--global-code-bg-color);
border-radius: 6px;
padding: 6px 12px;
text-align: left;
direction: ltr;
pre, code {
background-color: transparent;
border-radius: 0;
Expand Down
4 changes: 3 additions & 1 deletion _sass/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ body {
padding-bottom: 70px;
color: var(--global-text-color);
background-color: var(--global-bg-color);

unicode-bidi: bidi-override !important;
direction: unset !important;
Comment on lines +9 to +10
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I'm not as familiar with multi-directional language support. what does this do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I don't know much rather than bidi handles bi-directional scripting in the correct way. Often right-to-left scripts are not equal to a right-aligned version of a left-to-right script. Text becomes more shattered if there are numbers or special characters involved as well. Yet, with smart conditioning, one can prevent the misplacement of phrases. I guess, what bidi does is take care of all those cases.

Why these particular key-values are necessary to fix this, I don't know. I had this problem and (almost) followed the accepted answer. In my case, it worked.


h1, h2, h3, h4, h5, h6 {
scroll-margin-top: 66px;
}
Expand Down