Skip to content

Commit d40dce7

Browse files
committed
Ammended the README.md to include better information
1 parent 72aeb4e commit d40dce7

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

README.md

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
1-
## Python Arabic Reshaper
1+
## Python Arabic Reshaper
22
Reconstruct Arabic sentences to be used in applications that don't support Arabic
33

44
Based on [Better Arabic Reshaper](https://github.com/agawish/Better-Arabic-Reshaper/), ported to Python, tweaked a little bit.
55

6+
Arabic is a very special script language with two essential features:
7+
8+
1. It is written from right to left.
9+
2. The characters change shape according to their surrounding characters.
10+
11+
So when you try to print Arabic text in an application – or a library – that doesn’t support Arabic you’re pretty likely to end up with something that looks like this:
12+
13+
![Arabic text written from left to right with no reshaping](http://mpcabd.xyz/wp-content/uploads/2012/05/arabic-1.png)
14+
15+
We have two problems here, first, the characters are in the isolated form, which means that every character is rendered regardless of its surroundings, and second is that the text is written from left to right.
16+
17+
To solve the latter issue all we have to do is to use the [Unicode bidirectional algorithm](http://unicode.org/reports/tr9/), which is implemented purely in Python in [python-bidi](https://github.com/MeirKriheli/python-bidi). If you use it you’ll end up with something that looks like this:
18+
19+
![Arabic text written from right to left with no reshaping](http://mpcabd.xyz/wp-content/uploads/2012/05/arabic-6.png)
20+
21+
The only issue left to solve is to reshape those characters and replace them with their correct shapes according to their surroundings. Using this library helps with the reshaping so we can get the proper result like this:
22+
23+
![Arabic text written from right to left with reshaping](http://mpcabd.xyz/wp-content/uploads/2012/05/arabic-3.png)
24+
25+
## Usage
26+
27+
```
28+
import arabic_reshaper
29+
from bidi.algorithm import get_display
30+
31+
#...
32+
reshaped_text = arabic_reshaper.reshape(u'اللغة العربية رائعة')
33+
bidi_text = get_display(reshaped_text)
34+
pass_arabic_text_to_render(bidi_text)
35+
#...
36+
```
37+
38+
The `pass_arabic_text_to_render` function here is an imaginary function, it is just here to say that the variable `bidi_text` is the variable that you would need to use in your code afterwards, for example to print it in PDF, or to write it in an Image, etc.
39+
640
For more info visit my blog [post here](http://mpcabd.xyz/python-arabic-text-reshaper/)
741

842
## Known Issue
43+
944
[Harakat or Tashkeel](http://en.wikipedia.org/wiki/Arabic_diacritics#Tashkil_.28marks_used_as_phonetic_guides.29) are not supported, and I think that they can't be supported as their unicode characters are non-spacing marks (i.e. they don't take space, they are rendered in the same space of the character before them), which means that when used in a reshaper, they will be rendered on the next character as the text is reversed.
1045

11-
## License
46+
## License
47+
1248
This work is licensed under [GNU General Public License v3](http://www.gnu.org/licenses/gpl.txt).
1349

14-
## Demo
15-
* Online Arabic Reshaper: http://pydj.igeex.biz/arabic-reshaper/
50+
## Demo
51+
52+
Online Arabic Reshaper: http://pydj.igeex.biz/arabic-reshaper/
53+
54+
## Download
55+
56+
https://github.com/mpcabd/python-arabic-reshaper/tarball/master
1657

17-
## Download
18-
* Source Code: https://github.com/mpcabd/python-arabic-reshaper/tarball/master
58+
## Contact
1959

20-
## Contact
21-
* Abd Allah Diab (mpcabd)
22-
* Email: mpcabd {AT} G Mail (dot) COM
23-
* Blog: http://mpcabd.xyz
60+
Abdullah Diab (mpcabd)
61+
62+
Blog: http://mpcabd.xyz

0 commit comments

Comments
 (0)