Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arabic and English in same MySQL column come out mixed up

I am using PHP,Python and MySQL on a Macbook with OS10.10.5. I have the following sentence stored in MySQL:

enter image description here

However, when I use Python or MySQL to retrieve that string, it comes out as:

محمود السقا لـCNN: النظام يؤدب ثورة يناير

i.e. the letters and words get shunted around, e.g. the very first letter on the left hand side - in the original text its to the right of the CNN.

When I cut-and-paste from MySQL into TextEdit it comes out fine?!

I only seem to get this problem when I have any non-Arabic characters (e.g. C N N ") in my string???

Any advice appreciated.

Thanks.

like image 909
Bender Rodriguez Avatar asked Nov 17 '25 16:11

Bender Rodriguez


1 Answers

when I use Python or MySQL to retrieve that string, it comes out as: محمود السقا لـCNN: النظام يؤدب ثورة يناير

because the browser(or what ever it is drawing the letters) is using LTR direction

When I cut-and-paste from MySQL into TextEdit it comes out fine?!

because your TextEdit is using RTL direction


when you combine RTL language like Arabic in the same text with a LTR language like English you need to decide which context you are going to use depending on the amount of words from each language in the text, and that is to prevent the human reader from being confused.

Example-1

enter image description here (RTL)

"أحب من الإنجليزية كلمة "SUN" وهي تعني الشمس" (LTR)

Example-2

"from the Arabic language I like the word "شمس" which means the sun" (LTR)

enter image description here (RTL)


displaying example-1 using LTR direction would cause the words to be shunted around like the example you have given, because the amount of Arabic is too much. and displaying example-2 using RTL direction will do the same, because the amount of English is too much.

technically, the browser didn't do anything wrong, he just draw the letters he encounters in the string one after another according to the text direction he is using, only the human reader will be confused.


Let's get back to analyze what was happening in your example "محمود السقا لـCNN: النظام يؤدب ثورة يناير".

when you displayed the string using the browser, the browser was using LTR context, so this is what happened:

1- the browser starts to draw the characters he encounters "محمود السقا لـ". from left to right. this first part is all in Arabic, so far so good.

2- now the browser encounters the word "CNN" he draws it also from left to right -the browser doesn't know which language he is drawing, he just draw characters using the context you have chosen-

now the string is shown like this

"محمود السقا لـ" + "CNN"

3- the browser encounters the last part which is "النظام يؤدب ثورة يناير", he draws it also from left to right without any awareness which characters are those! , now the displayed text is shown like this

"محمود السقا لـ" + "CNN" + "النظام يؤدب ثورة يناير"


now what happened with your TextEdit is that he did exactly what the browser did, except he is using RTL context , which will result in putting the same 3 parts of the sentence in the same order like the browser did, but starts from RIGHT to left which will result in the correct form (from the human reader point of view)

SUMMERY when you combine multiple directions languages in one text, use the right context that will result in a better view for the human reader


this is how you change the Direction in note++

LTR

enter image description here

enter image description here

RTL

enter image description here

enter image description here

like image 158
Accountant م Avatar answered Nov 19 '25 06:11

Accountant م



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!