chatterino2 icon indicating copy to clipboard operation
chatterino2 copied to clipboard

Implement initial support for RTL languages

Open mohad12211 opened this issue 3 years ago • 7 comments

Pull request checklist:

  • [x] CHANGELOG.md was updated, if applicable

Description

image

This is a dirty fix #720 for RTL languages. I don't have much experience with C++, the code is not well-structured and not optimized, but it is a try.

  • [ ] Selection do not work yet.
  • [ ] Neutral words (words that contain number, non-alphabetical characters like & $ # etc...) won't be ordered correctly in RTL mode, this is due to QString::isRightToLeft() returning false both on LTR and neutral words. this can also make the mode LTR when the text starts with a neutral word, when it should be RTL because the first non-neutral word is RTL.

this differs from #1970 by:

  • [x] punctuation marks are displayed properly.
  • [x] mixing RTL and LTR works (the correct way, not Twitch's way)
  • [x] line breaks also work.

should be a slightly better temporary fix, please tell me if there are more issues other than the ones I mentioned. I will try to fix the remaining issues and refactor the code after that, any help/tips on how to structure the code are very appreciated!

mohad12211 avatar Sep 08 '22 22:09 mohad12211

The last commit should show proper mixing between RTL and LTR, Twitch is doing it the wrong way actually. If the text starts with an RTL word (e.g. Arabic), with LTR in the middle, it will only swap the RTL sequences, which is wrong, and a frustrating issue on Twitch... Should be working here. And it makes emotes show in the correct way as well. Example: image

mohad12211 avatar Sep 09 '22 16:09 mohad12211

The artifacts to test these changes can be found here, incase any issues can be found by native RTL speakers.

image

Felanbird avatar Sep 09 '22 22:09 Felanbird

thank you so much! Everything seems to work correctly so far.

EndlessJest avatar Sep 14 '22 08:09 EndlessJest

~~From a functionality standpoint, it appears these changes push the "space" when using large emotes to the bottom, instead of the top of the message.~~ resolved

before: image

after: image

Felanbird avatar Sep 16 '22 20:09 Felanbird

@Felanbird yes that was due to a weird thing I did, fixed after this refactor.

mohad12211 avatar Sep 16 '22 21:09 mohad12211

I refactored the fix a bit.

What is done is basically this: we call _addElement normally, if we detect an RTL word in the container, we reorder the elements. we call addElement on each element again, without adding the element to this->elements_, if the text starts with an RTL word, we render from right to left (so currentX_ will decrease instead of increase), otherwise render normally since we are calling _addElement in the correct order. since we need the previous element for Compact-Emotes, I pass the index for the previous element, I pass -2 by default, so that in the first call we just do it the old way, the second call it will start from -1. I think this is better than making two _addElement functions, one for RTL and one for LTR with 90% similar code. let me know if I can do it in a better way.

mohad12211 avatar Sep 16 '22 21:09 mohad12211

image ~~Top portion is this PR - bottom is normal chatterino incorrect rendering~~ resolved

Felanbird avatar Sep 17 '22 03:09 Felanbird

Everything should be working now except selection, copying the entire message works for now as an alternative to selection. I will see what I can do about selection soon. Please test this as much as possible, preferably with other RTL languages other than Arabic. To download the app with this changes. go to Checks, at the top, then build, then at the bottom you will find binaries for all operating systems: image image

mohad12211 avatar Oct 31 '22 17:10 mohad12211

ready for final review & merge.

mohad12211 avatar Nov 10 '22 18:11 mohad12211

Looks like this for me (left = your PR, right = master) image

Testing with this text: a یک دو سه b

pajlada avatar Nov 10 '22 19:11 pajlada

When switching to Segoe UI it looks correct to me

image

pajlada avatar Nov 10 '22 19:11 pajlada

I attribute the previous errors I ran into to bad fonts on Linux

pajlada avatar Nov 10 '22 19:11 pajlada

@mohad12211 Thanks for your contribution! As a first-time contributor, you can now add yourself to the contributors list that's shown inside the application.

To do so, open a new PR where you modify the resources/contributors.txt file and add yourself to the list. Make sure to read the comments at a top for instructions.

Felanbird avatar Nov 10 '22 20:11 Felanbird