# Recommended way to handle RTL mixed with LTR languages

**URL:** https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894
**Category:** Support
**Created:** [24.Январь.2018 17:24:26 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894 "2018-01-24T17:24:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![GiorgosK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/giorgosk/32/83413_2.png) [@GiorgosK](https://meta.discourse.org/u/GiorgosK)
#### Post date: [24.Январь.2018 17:24:26 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/1 "2018-01-24T17:24:26Z")

</div>

The forum we are running is mainly in english but we have some pages recently that are RTL (arabic)  
what is the recommended way to get a specific topic to have RTL direction

is this the only posibility ?

> [@Support RTL blocks for LTR-layout website and vice versa](https://meta.discourse.org/t/support-rtl-blocks-for-ltr-layout-website-and-vice-versa/48599):
>
> Users would like sometimes to write both RTL and LTR text in one single post. Right now, the direction of everything in the website (including text editor and posted posts) depends on the layout of the language used. Arabic means RTL and English means LTR. It would be helpful if one can choose that he wants these paragraphs to be opposite the direction of the website. I tried: \<div dir="rtl"\> … \</div\> to force a direction change since HTML is supported, but that didn’t do anything, even if i…

is this a plugin that can handle the tags [text-direction=rtl] [/text-direction]

any other way ?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [24.Январь.2018 17:33:58 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/2 "2018-01-24T17:33:58Z")

</div>

We are going to be adding a site setting for supporting mixed text direction very soon. I’m working on it now.

---

<div class="post-metadata">

### Author: ![GiorgosK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/giorgosk/32/83413_2.png) [@GiorgosK](https://meta.discourse.org/u/GiorgosK)
#### Post date: [24.Январь.2018 17:34:36 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/3 "2018-01-24T17:34:36Z")

</div>

so the plugin is not really supported ?  
should it be avoided ?  
will it cause trouble if you solution comes out ?  
any ETA on your solution ?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [24.Январь.2018 19:37:59 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/4 "2018-01-24T19:37:59Z")

</div>

I haven’t looked at that plugin in a while. I wouldn’t recommend using it. For now, the best way to get RTL content to display correctly when a LTR locale is being used is to wrap the content in `<div dir="rtl"></div>` tags. Doing this won’t cause any trouble when support for mixed text direction is added. The ETA for that feature is early next week.

---

<div class="post-metadata">

### Author: ![GiorgosK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/giorgosk/32/83413_2.png) [@GiorgosK](https://meta.discourse.org/u/GiorgosK)
#### Post date: [24.Январь.2018 20:09:31 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/5 "2018-01-24T20:09:31Z")

</div>

Thanks for the answer  
I tried both `<p class="rtl"></p>` and `<p dir="rtl"></p>` inside a post but I end up with `<p></p>` in both cases

So its strips out the attributes, how can I tell discourse to not strip those attributes ? is there a setting ?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [24.Январь.2018 22:27:17 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/6 "2018-01-24T22:27:17Z")

</div>

> [@GiorgosK](#):
>
> I tried both \<p class=“rtl”\>\</p\> and \<p dir=“rtl”\>\</p\> inside a post but I end up with \<p\>\</p\> in both cases

Sorry, the `dir` attribute is only whitelisted for `<div>` tags.

`<div dir="rtl">this is a test</div>` will work:

There is no setting to add attributes to the Discourse whitelist. It can be done through a plugin. That’s what the plugin that you linked to is doing.

---

<div class="post-metadata">

### Author: ![GiorgosK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/giorgosk/32/83413_2.png) [@GiorgosK](https://meta.discourse.org/u/GiorgosK)
#### Post date: [25.Январь.2018 07:46:56 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/7 "2018-01-25T07:46:56Z")

</div>

Great thanks that worked

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [25.Январь.2018 08:13:17 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/8 "2018-01-25T08:13:17Z")

</div>

Great job! I’ve been looking for this feature. Is it automatic? like suggested here?

> [@Set direction of text depending on text itself](https://meta.discourse.org/t/set-direction-of-text-depending-on-text-itself/54016):
>
> Facebook has it ! [image] When Writing with an RTL language the ticker goes to the other way which gives a very intuitive experience. I need this for my community because we are bilingual. Thanks Discourse … Love

Or is it a button to change the direction of text?

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [25.Январь.2018 08:26:41 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/9 "2018-01-25T08:26:41Z")

</div>

Any reason we don’t enforce `dir="auto"` ?

> **[dir HTML global attribute - HTML | MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/dir)**
>
> The dir global attribute is an enumerated attribute that indicates the directionality of the element's text.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [25.Январь.2018 17:33:42 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/10 "2018-01-25T17:33:42Z")

</div>

> [@j.jaffeux](#):
>
> Any reason we don’t enforce dir=“auto” ?

It’s doesn’t get inherited, so it would need to be applied to every element in a cooked post. Also, Internet Explorer doesn’t support it. If we’re not concerned about supporting IE, there are places in the code that it would be useful (titles, category descriptions, etc.), but it’s easy enough to add a helper function that sets the direction of those elements based on their text content.

> [@parisa](#):
>
> Is it automatic?

It automatically applies the correct direction to text in the preview window, cooked posts, titles etc. It sets the direction of text fields based on the text that is entered. It doesn’t automatically set the direction of the composer’s textarea. To make it easier to type, you can switch the direction of the textarea by clicking a button. Changing the textarea’s direction doesn’t affect its final output. It will be formatted correctly regardless of the direction the textarea is set to.

Facebook’s editor handles text direction very well. They can do this because their editor is using contenteditable. This lets them set the text direction on individual elements in the editor. It’s possible to get behaviour similar to this by adding the attribute `dir="auto"`to the composer’s textarea, but doing that has some strange side effects.

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [06.Февраль.2018 11:37:48 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/11 "2018-02-06T11:37:48Z")

</div>

any update for this feature?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [06.Февраль.2018 16:30:59 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/12 "2018-02-06T16:30:59Z")

</div>

It is available in the master branch now. Enable it by selecting the support\_mixed\_text\_direction setting. I’ll write a topic about it soon.

There are a few improvements that could be made to the way it’s setting the text direction for topics. The biggest problem I’m seeing with it is that usernames need to be treated as a special case.

To get category descriptions to display correctly on the categories page, you need to add this css to your theme. I’ll make a pull request to add that to the main code.

```css
.category-description span {
    display: inline-block;
}

```

The button for toggling the editor’s direction is found here. Toggling the editor’s direction doesn’t affect the editor’s output, it just makes it easier to type.

 ![36%20AM](https://global.discourse-cdn.com/meta/original/3X/8/4/842d3802211c0ba5467d7e8177fc342722dc4730.png)

There are still a few areas where mixed text could be displayed that are not having their text-direction set. If you come across any, please let us know.

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [07.Февраль.2018 04:00:05 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/13 "2018-02-07T04:00:05Z")

</div>

Fantastic! I have updated discourse to latest and it is working like a charm.

> [@simon](#):
>
> The button for toggling the editor’s direction is found here. Toggling the editor’s direction doesn’t affect the editor’s output, it just makes it easier to type.

My first comment would be if you can do something for this button to not toggle entire editor and just toggle current paragraph. That would be great.

I keep an eye on this new feature and let you know about problems.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [07.Февраль.2018 17:53:30 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/14 "2018-02-07T17:53:30Z")

</div>

I would love to support partial ltr/rtl to be visible in the composer but it will require a pretty big change to the composer cause we can no longer use a text area and would have to use a content editable div

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [07.Февраль.2018 17:59:45 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/15 "2018-02-07T17:59:45Z")

</div>

So maybe removing that button is better. because at least for my community, it is confusing the ppl. they think that it is that button that decides the direction of text.

another question.

 ![Screenshot-2018-2-7%20%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%20%D8%B1%D9%88%D8%B4%20%D8%AE%D9%88%D8%AF%DA%A9%D8%A7%D8%B1%20%D8%AC%D9%87%D8%AA%E2%80%8C%D8%AF%D9%87%DB%8C%20%D9%85%D8%AA%D9%86%20%D8%A7%D9%86%DA%AF%D9%84%DB%8C%D8%B3%DB%8C%20%D9%88%20%D9%81%D8%A7%D8%B1%D8%B3%DB%8C](https://global.discourse-cdn.com/meta/original/3X/6/a/6a435bcb77036c6158f670b07d84fe4b43ebe79c.png)

I realized that to change the direction of text, rtl and ltr contents should be separated by two enters. Can you also support correct direction with one enter?

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [07.Февраль.2018 20:25:53 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/16 "2018-02-07T20:25:53Z")

</div>

> [@parisa](#):
>
> So maybe removing that button is better.

Please ignore this suggestion. It is good when it comes to a full ltr/rtl post.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [07.Февраль.2018 20:27:40 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/17 "2018-02-07T20:27:40Z")

</div>

Thanks for the feedback! One of the main reasons for adding the button was to make it easier to add blocks of code on RTL sites.

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [09.Февраль.2018 18:28:21 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/18 "2018-02-09T18:28:21Z")

</div>

Is this possible @simon ?

> [@parisa](#):
>
> I realized that to change the direction of text, rtl and ltr contents should be separated by two enters. Can you also support correct direction with one enter?

non tech people don’t understand the difference between one and two enters.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [09.Февраль.2018 18:41:15 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/19 "2018-02-09T18:41:15Z")

</div>

I think it is possible, but I’m not sure how efficient it will be. I’ll give it a try.

The easiest non-technical explanation for the difference between one and two enters is that two enters (a blank line) creates a new paragraph. The direction is being set at the paragraph level.

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [12.Февраль.2018 07:17:26 UTC](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894/20 "2018-02-12T07:17:26Z")

</div>

@simon, I found that there is a great performance drop in long topics containing mixed text direction. First I thought its because of [rating plugin](https://meta.discourse.org/t/topic-ratings-plugin/39578/144). However after further examination, I turned off this feature in our forum, and found that everything was back to normal.

[Следующая страница](https://meta.discourse.org/t/recommended-way-to-handle-rtl-mixed-with-ltr-languages/78894.md?page=2)
