Lib Arabic Reshaper

Lib Arabic Reshaper

1.3k Downloads

Arabic Reshaper LUA

The Arabic Reshaper for WoWinArabic addons is a powerful tool that enables the reshaping of Arabic characters to improve the overall appearance and readability of text. It ues a table of reshaping rules for Arabic characters, including letters and ligatures, to ensure that the text is displayed correctly in games such as World of Warcraft or any other game that accepts Lua.

The reshaper uses the position of each letter in the text to determine the reshaping. For instance, if the letter is at the beginning of the word, it will be reshaped as an "initial" form, while if it's at the end of the word, it will be reshaped as a "final" form. The reshaper also takes into account the characters that come before and after the current one to determine the correct reshaping. Additionally, it can handle ligatures of 2 or 3 characters.

This reshaper is essential for those working with Arabic text in the gaming industry, or for anyone looking to enhance the aesthetics of their Arabic text. Developed by Platine, and based on the UTF8 library by Kyle Smith, it offers a user-friendly interface and powerful reshaping capabilities. Obtain it now and effortlessly improve the readability of your Arabic text.

Working on the library took a lot of work, so if you would like to respect our work and contribute to the further development of the project - support the project with a donationHow much is this library worth to you? You will find the donation button on the right.

 

https://WoWinArabic.com

 

 Installation

To use this library, simply copy the AS_Reshaping.lua file into your project's directory and require it in your code:

local AS_Reshaping = require("AS_Reshaping")

 

Usage

 

To reshape Arabic text, call the AS_reshaping() function and pass it a string of Arabic text. The function returns the reshaped text as a string.

local reshaped_text = AS_Reshaping.AS_reshaping("اللغة العربية هي لغة جميلة")
print(reshaped_text)
Output: ﺔﻴﻟﺮﻌﻟا ﺔﻴﺒﺭﻷا ﻩﻮﻟﺍ ﺔﺳﻮﻠﻋ جميلة لغة هي عربية ال

To reverse the order of letters in a UTF-8 encoded string, call the AS_UTF8reverse() function and pass it the string. The function returns the reversed string.

local reversed_text = AS_Reshaping.AS_UTF8reverse("اللغة العربية هي لغة جميلة")
print(reversed_text)
Output: ةيلمج ةغل ليه يبرععلا ةيلغلا

The library contains the letter form assignment tables (isolated, initial, middle, final)

 

AS_Reshaping_Rules = {
["ا"] = {isolated = "ا", initial = "ا", middle = "ﺎ", final = "ﺎ"},-- ALEF
["ﺁ"] = {isolated = "ﺁ", initial = "ﺁ", middle = "ﺂ", final = "ﺂ"},-- ALEF WITH MADA ABOVE
["أ"] = {isolated = "أ", initial = "أ", middle = "ﺄ", final = "ﺄ"},-- ALEF WITH HAMZA ABOVE
["إ"] = {isolated = "إ", initial = "إ", middle = "ﺈ", final = "ﺈ"},-- ALEF WITH HAMZA BELOW
["ب"] = {isolated = "ب", initial = "ﺑ", middle = "ﺒ", final = "ﺐ"},-- BA
["ت"] = {isolated = "ت", initial = "ﺗ", middle = "ﺘ", final = "ﺖ"},-- TA
["ث"] = {isolated = "ث", initial = "ﺛ", middle = "ﺜ", final = "ﺚ"},-- THA

...

as well as ligatures of 2 and 3 letters.

 

Functions in library:

 

-- returns the number of bytes used by the UTF-8 character at byte
function AS_UTF8charbytes(s, i)

 

-- returns the number of characters in a UTF-8 string
function AS_UTF8len(s)

 

-- function finding character c in the string s and return true or false
function AS_UTF8find(s, c)

 

-- functions identically to string.sub except that i and j are UTF-8 characters (instead of bytes)
function AS_UTF8sub(s, i, j)

 

-- reverses the order of UTF-8 letters
function AS_UTF8reverse(s)

 

License

This library is released under the MIT License. See the LICENSE file for more information.