Supporting mixed text directions

:bookmark: This document explains what the “support mixed text direction” setting does in Discourse, how it works, and how it impacts post composition.

:person_raising_hand: Required user level: Administrator

The ‘support mixed text direction’ setting is crucial for sites that feature both left-to-right (LTR) and right-to-left (RTL) languages. Enabling this setting ensures that Discourse automatically adjusts the text direction for various elements like post content, topic titles, category names, and the composer’s preview area based on the language detected. Additionally, it sets the text direction for text inputs according to the user’s language input. As long as the content is separated by a newline, it allows you to have mixed text within an individual post.

Summary

This documentation will cover:

  • How the ‘support mixed text direction’ setting works
  • Its impact on content display
  • How it affects post composition
  • Best practices and common issues

How it works

The support mixed text direction setting only affects the content’s display in the browser. It doesn’t alter the content stored in the database. When enabled, Discourse adds the dir="auto" attribute to HTML elements such as post paragraphs, topic titles, category names, and text inputs. The browser then automatically determines and applies the correct text direction based on the content of each element.

Composing a post

When composing a post, text inputs automatically detect the direction of the text being entered thanks to the dir="auto" attribute. To assist with mixed text direction needs, the setting also introduces a Toggle Direction button in the composer’s toolbar. Clicking this button switches the direction of the entire textarea.

In the composer’s preview area, the text will display with the correct direction regardless of the textarea’s current direction.


Best practices

  1. Enable this setting if your community frequently uses both LTR and RTL languages.
  2. Use the Toggle Direction button to adjust text direction when composing posts to ensure readability.
  3. Inform users about the Toggle Direction button for better usability in mixed-language posts.

Common issues and solutions

  1. Text alignment not appearing correctly: Ensure the setting is enabled. The browser’s dir="auto" determines direction from the first strong directional character in each element.
  2. Quoted text direction: Quote titles always follow the site’s language direction, while quoted paragraphs use dir="auto" for automatic detection.

FAQs

Q: What happens if the setting is disabled?
A: Text direction will not automatically adjust based on the language, which can cause readability issues in mixed-language posts.

Q: Does it change the actual content in the database?
A: No, it only affects how content is displayed in the browser.

Q: Can I manually set text direction without this setting?
A: Yes, but enabling this setting simplifies the process and ensures consistency across the site.

Last edited by @hugh 2024-06-17T10:21:14Z

Last checked by @hugh 2024-06-17T10:21:21Z

Check documentPerform check on document:
11 Likes