IngoMeyer441 / simple-term-menu

A Python package which creates simple interactive menus on the command line.
MIT License
492 stars 43 forks source link

Add RTL support #88

Open yarons opened 7 months ago

yarons commented 7 months ago

Some projects using this library have been translated into RTL languages like Arabic, Urdu, and Hebrew.

The menus should support aligning to the right instead of the left to make the user interface more suitable for RTL users.

Example of a menu: תמונה

IngoMeyer441 commented 7 months ago

Thanks for your request. I am not familiar with RTL languages (my mother tongue is German). Is this "only" an aligning problem, or is it also necessary to mirror the menu items (the underlying Python strings) before they are displayed?

yarons commented 7 months ago

Great question, thank you :)

Well, in the Archinstall script, for example, you would see something like:

Select timezone UTC

The title is aligned to the left according to the beginning of the line in English. In Hebrew, I would expect to see it the other way around:

בחירת אזור זמן UTC

Regarding the order of the letters internally, that's another problem; Hebrew strings are sorted in arrays the same way English or Latin strings would; the difference is the "directionality" of the individual character, which is usually handled by the display that renders those (Pango\HarfBuzz\etc.) This problem was already solved by a competent and efficient library called FriBiDi, and it has an excellent Python implementation called pyfribidi; the main advantage is that this library makes all the complicated decisions for you so if you're unsure if this string is in English/Hebrew it will handle every character individually so the English text won't be reversed and vice versa.

Some terminal emulators support RTL natively, so the main problem is usually the Linux kernel terminal. There is an open proposal to implement RTL as a first-class citizen in the Linux kernel terminal, but I haven't seen any intentions to follow it over the past couple of years.

Herzlichen Dank!