Right-to-left development: Tips and tricks

19 May 2017
Right-to-left development: Tips and tricks

Authoring an RTL website is an unconventional task, even for an experienced frontend developer. Since languages that are read from right to left, such as Arabic, Persian, Hebrew, Urdu, etc., involve making particular changes to the development process, there are a number of specific details that need to be taken into account by developers.

In our previous article, we talked about RTL website design. In this post, we’ll take a look at the peculiarities of building RTL websites and bidirectional websites.

Creating right-to-left websites: Characteristics to take into account

1) In RTL language regions, people read and write from right to left. This means that most interface elements should be flipped in order to be displayed correctly.

2) Elements connected with media-content management, such as “Play” in a video player, don’t need to be mirrored.

3) The order of digits in numbers (such as phone numbers) doesn’t differ from left-to-right writing.

4) Overlining is usually used to highlight text in Arabic (instead of underlining, italics, or interspacing).

649aa252-eb6a-46a4-b22e-2452e8f67704.png.930x0_q90

5) Capital letters are often omitted.

e4fbbe15-f691-4e67-b2d7-ca4eb472d796.png.930x0_q90

6) Although intellection and visual information perception have an identical direction of writing – RTL, most people are right-handed. Therefore, it’s better to not mirror some controls so that users can interact with them comfortably. Centering controls and creating a “liquid layout” can help avoid confusion and can better the user’s experience with the website.

7) When combining symbols that can be used in both RTL and LTR languages (such as periods, commas, or other punctuation marks), their displayed positions will depend on the direction of the text. This is because the data format starts from the beginning, but a browser is still processing an RTL word in the RTL direction and punctuation is converted towards the direction that has been specified.

This can be seen in the following example:

b07fef56-3089-4e0e-906d-9a275120f673.png.930x0_q90

To avoid these results when combining RTL and LTR strings or text fragments, they should be converted into separate elements that specify their direction using the dir attribute or a css direction property.

wmqji 2023-10-03 22-22-40

or another variant

q6ki5 2023-10-03 22-22-54

To prevent these problems, <bdi> tag can also be used. The given tag is supported only by Chrome (16) and Firefox (10).

8) When writing basic css styles, a separate file for RTL CSS direction should be created where the horizontal properties are set (float, left/right, padding-left/padding-right, margin etc.) and redefined appropriately:

yel0m 2023-10-03 22-23-05

rtl.css file:

5wuhd 2023-10-03 22-23-14

In this case, the two files are appended at the markup stage and the finished product results in one common file that meets the relevant conditions.

To eliminate additional LTR-directed features, a separate ”rtl.css” can be attached if it’s necessary.

Another way to achieve this result is to create two complete style files for RTL and LTR. There are utility programs that can help automate the styles assembling.

One tool that can do this is css-flip, a utility created in the bowels of Twitter. It allows developers to compile a file with redefined properties for RTL from the source file.

input.css:

mmly4 2023-10-03 22-23-24

Replacements and exceptions based on directives in the source file may be used as well.

Example:

input.css:

9t7a1 2023-10-03 22-23-58

output.rtl.css:

3rla7 2023-10-03 22-24-04

A similar tool is RTLCSS. It also supports replacements or exceptions and it allows developers to rename selectors, add local configurations of exception, and delete or add new properties.

Example:

input.css:

3lz5g 2023-10-03 22-27-01

output.rtl.css:

webd6 2023-10-03 22-27-17

Configurations for renaming selectors can also be done.

input.css:

558dk 2023-10-03 22-41-44

output.rtl.css:

jmtmo 2023-10-03 22-41-53

9) Calendar display is another important aspect to take into account because calendar years also vary between LTR and RTL regions.

For example, the Islamic calendar (Hijri) is a purely lunar calendar. It contains 12 months that are based on the moon's phases, which means that the Islamic calendar year works out to be shorter than the non-Islamic calendar year: 12 x 29.53 = 354.36 days. The Gregorian calendar, which is most commonly used in LTR, is calculated according to the Earth’s rotation around the Sun, meaning that a Gregorian year is longer than a non-Gregorian year. That’s why Hijri always has to shift according to the Gregorian calendar.

Due to these variations, it can be difficult to find a high-quality tool for working with both Gregorian calendars in LTR script and so-called non-Gregorian calendars in RTL script simultaneously.

Fullcalendar is a very popular jQuery calendar that completely relies on moment.js in time calculation. However, this tool isn’t capable of accomplishing conversions between different kinds of calendars. It only makes it possible to display RTL content and localize dates.

Dojo Toolkit, on the contrary, has the ability to display non-Gregorian calendars. However, the range of tasks that it can carry out is limited.

10) Although many languages allow for the abbreviation of the names of days of the week to save space, this approach is not useable in Arabic where the names of all the days begin with the same letter.

0198e8b0-4db9-4048-9631-f23e6578e377.png.930x0_q90

11) Internationalization API support covers a wide spectrum of languages and their derivatives. The Intl object is the namespace for the ECMAScript Internationalization API. This API provides a language-sensitive string comparison, as well as relevant number, date, and time formatting. It supports not only Arabic, but also Arabic-Arabic, Arabic-Tunisian, and a wide range of other variants.

The use of Eastern Arabic numerals instead of Western numerals can also vary. In some varieties of this language, Eastern Arabic numerals (123) are used instead of Western (١٢٣). The API can help indicate when to show ١٢٣ and when to show 123.

Examples:

Formatting of Arabic-Egyptian numerals:

zwidf 2023-10-03 22-27-54

For instance, Tunisia features Eastern Arabic numerals:

ejhqo 2023-10-03 22-44-37

DateTimeFormat constructor is an irreplaceable property of the Intl object. It allows for passing additional options in the argument string to specify formatting for date and time.

As an example, this is how to convert a date from the Gregorian calendar into the Islamic calendar:

xas2r 2023-10-03 22-28-19

Additional resources for RTL website development

They say that “forewarned is forearmed”. We hope this post has been useful in highlighting the peculiarities and specifics of working on RTL projects. These recommendations should help developers choose an appropriate strategy to avoid mistakes to develop a right-to-left website quickly and effectively.

We also welcome you to read an article that explains how to design for right to left languages.

As a software company, we’ve been engaged in Arabic website development and Arabic website design. Feel free to navigate our portfolio to learn about our experience in the industry.

For additional resources and more information about RTL development, please check out these useful links:

  1. Authoring HTML: Handling Right-to-left Scripts
  2. Intl API
  3. Working with bidirectional (bidi) text and RTL languages on the web