How to Implement a Better PHP Arabic Text Display Solution - PHP AWR class package blog

Recommend this page to a friend!
  All package blogs All package blogs   PHP AWR class PHP AWR class   Blog PHP AWR class package blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Implement a Be...  
  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author:

Updated on: 2021-03-10

Posted on: 2021-03-10

Package: PHP AWR class

Rendering text in the Arabic language is a challenge because not only it requires displaying text using letters of an alphabet that is distinct from the Latin alphabet, but it also requires rendering text from the right side to the left.

Read this article to learn how to solve the challenges of displaying text in Arabic using the AWR class.




In this article you will learn:

Why the AWR Class Was Developed

What Are the Problems that the AWR Class Aims to Solve

How to Download or Install the PHP AWR Class So You can Display Arabic Text in a Better Way


Why the AWR Class Was Developed

I have been working on this class since 2014. I updated the code 2 times since the first release. In version 2.0 the whole code was rewritten.

The idea behind this class is that we can apply tajwid rules to a class that can show every word for that rule with a different color in the main text.

What Are the Problems that the AWR Class Aims to Solve

The first challenge was splitting words in their current form. Arabic words have 4 shapes: middle shape, end shape, first shape, single shape) and there is erab (Irab). erab is the most important part of this project.

As far as I knew, there was no PHP class that could do that in the way that is needed in this project. So I ended up using PHP persian_log2vis class which can handle all it needs for this project.

The next part of this project was understanding the tajwid rules. tajwid rules define the way characters should sound if they are in certain order or position.

For example imagine a tajwid rule is like this : if "A" or "B" is followed by "C" and it is at the end of the word it must sound without the "C".

So if the word is "nnnbc" the bc at the end will be displayed in a different color, so a person that reads a word can understand that the word must be read without the c .

To make this happen, we must check every character in Arabic words with 4 - 5 letter after them to check for the rules. If the rule is applied we must tag the word that is applied to the rule, so we display it with a different color in the main string.

Maybe that is easy for an English word. But if you split the Arabic words the usual way you cannot glue them together the way they were (middle, end, start, single), as they become separated and will loke unreadable.

I used a library that can split and output the characters the way they are with their erab because after the processing is finished I want to show the characters in a box with different colors.

Anyway, for every rule we want apply, we need every character that started the rule application, an erab or characters that is attached with first character, a character that is followed with this sequence and an erab or character that is attached by the word before.

Also we want to check that if the rule is applied to the character at the end of each word, for all of these words, we need an optimized function that can do everything simply just by putting the words in place. So it is so easy to use, that everyone can add they word rules and color the applied words.

For every word we need the Unicode character values (every word = 4 unicode values) in an array that is passed to a custom function that we can use to process the event in order to be used in a class .

Another difficulty was that these rules can be applied for the words that have the additional erab, the silent word in the middle of the word. So we must check for them everytime.

After everything was finished, we need to glue erabs with the words before them because an erab cannot be used in the single form. We just split words there by checking every character in the array.

After this everything is finished, we just need to output the results. However HTML does not support the word coloring in a simple way. So I end up using an invalid tag (<n>) to show every word character and color them using CSS styles. 

The first two versions of the class had a lot of code using condition check with the if statement. For every rule, I was checking the word from start to end in there 3 forms (rule from start to end, rule from end to start and rule in the middle). The code was very messy but it served as proof of concept.

After that version I added the array tag method. Next I wrote the wordrule_applyer method, so it can handle all of the logic this project needs in a clean and optimized way.

For all the years I worked on this class, I tried to show that how amazing this project is but I failed every time because to understand this project you must understand all the hard works and love that is put in this project.

After the code was cleaned, I converted all the codes to c# and write a desktop app for the project you can download the program from rokhan. The c# library will be available on my github soon. I hope that my works are helping others in their project and this project is recognized the way that it deserves.

How to Download or Install the PHP AWR Class So You can Display Arabic Text in a Better Way

The PHP AWR Class can be downloaded as a compressed archive or installed using PHP Composer following the instructions available in the package page.

Feel free to try it share your feedback here below this article or ask questions in the class support forum.




You need to be a registered user or login to post a comment

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

No comments were submitted yet.



  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  
  All package blogs All package blogs   PHP AWR class PHP AWR class   Blog PHP AWR class package blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Implement a Be...  

For more information send a message to info at phpclasses dot org.