Reputation: 3205
I need to reverse the text direction of an arabic string in perl as I have done it in this Fiddle using CSS. I am a newbie in perl, so I need some guidance to get my expected result.
I am looking for exactly same results as shown in the Fiddle. I have tried it using an advice in this StackOverflow Question.
But this code is actually reversing the order of words in the text. If i do the same with arabic text, it will change its meaning.
Thanks for help.
Upvotes: 1
Views: 1474
Reputation: 111239
You should store text always in writing order. The direction of text is a property of the Unicode characters that you use, and the programs used for reading text (text editors, web browsers, ..) should implement the Unicode bi-directional text algorithm to show it correctly. If you are writing a program to display text (as opposed to just generating it), you will find the Text::Bidi CPAN module helpful.
With certain mixtures of right-to-left and left-to-right languages the bi-di algorithm may get something wrong. In these cases you can add Unicode directionality marks into your output. For example, if a paragraph in Arabic happens to begin with an English product name you can insert an RTL mark in the beginning so that the whole paragraph is properly displayed. In Perl:
my $RLM = "\x{200F}"; # Unicode RIGHT-TO-LEFT MARK
say "${RLM}Quux ﻢﻧ ﺎﻠﻣﺎﻠﻛ: \"Centre D\'affaires\"";
Upvotes: 3