soimort / translate-shell

:speech_balloon: Command-line translator using Google Translate, Bing Translator, Yandex.Translate, etc.
https://www.soimort.org/translate-shell
The Unlicense
6.83k stars 387 forks source link

keep bidi support as non-default behavior #464

Closed usama-makhzoum closed 8 months ago

usama-makhzoum commented 1 year ago

Arabic script (used also in many languages) needs to have both bidi and font-shaping support in order to have it read properly

translate-shell has a pseudo facility to display the arabic script in terminals that don't support bidi, and this is the default behaviour when choosing language targets to be arabic or farsi. however as of 2019 most terminals has bidi and shaping support provided because of the newer Gtk VTE features. now pseudo bidi in translate shell makes that scripts unreadable in that terminals as bidi-and-shaping process is done twice actually.

currently user can disable translate-shell bidi via -no-bidi option, maybe should make the enabling bidi as the option (-with-bidi) and disabling pseudo bidi by default as most of mac and linux terminals now support it already out of box.

soimort commented 1 year ago

currently user can disable translate-shell bidi via -no-bidi option,

One trick to disable translate-shell's bidi by default, is to add

  :no-bidi true

in the configuration file.

I can confirm that newer VTE does bidi transformation automatically, however this may not be generally true for older distros, and there are also a lot of non-VTE emulators which do not have this (according to https://gist.github.com/XVilka/a0e49e1c65370ba11c17). So, a more proper default behavior would be to detect if the terminal emulator has embedded bidi support and perform bidi transformation only if needed (so as not to transform the right-to-left text twice).

usama-makhzoum commented 1 year ago

I can confirm that newer VTE does bidi transformation automatically, however this may not be generally true for older distros, and there are also a lot of non-VTE emulators which do not have this (according to https://gist.github.com/XVilka/a0e49e1c65370ba11c17). So, a more proper default behavior would be to detect if the terminal emulator has embedded bidi support and perform bidi transformation only if needed (so as not to transform the right-to-left text twice).

I am afraid that terminal emulators don't provide any info or flags that indicate bidi is provided in there

maybe should suggest it to VTE's developers as many other TUI apps have similar issues (including vim and emacs)?

One trick to disable translate-shell's bidi by default, is to add

i've forgotten about conf, totally.

soimort commented 8 months ago

trans will stop doing its own BiDi transform for terminals based on newer VTE versions. Specifically, it checks if the env variable $VTE_VERSION is greater than 5703 (since vte 0.57.3 is the first version that implements RTL/BiDi support according to this).

If anyone encounters RTL rendering problems under non-VTE terminals, feel free to open a separate issue.