How to display numbers in Arabic language?

Hi Experts,

I am writing an Arabic application. I wonder how can i write the numbers in Arabic when i am using the display.newText because I want to display the result in Arabic numbers not English since it is Arabic app. I need you support …

i am attaching picture to show the Arabic numbers for whom who don’t know them. 

Regards

Abdulaziz

If your file is saved in utf8 format (without BOM) and your font supports arabic characters then you can just pass string with arabic text to display.newText

Piotrz55,
Can you please explain more your answer? Which files do you mean… i appreciate if you can write simple example…
Also for your informatiom i can pass arabic text and it works thru display.nextText… only i cant type arabic numbers as they come in english even i am typing in arabic.
Regards
Abdul

I cannot write sample be because there is no sample as such. When you create file your editor have options to save file in different encodings: ascii, utf8… To support not english characters you must save file in utf8 format (I’m not talking about .lua extension).

You mean you want to have your arabic ‘1’ instead of 1 in code? If so then not possible, only english syntax and latin numbers.

If you want to have arabic ‘1’ displayed on screen then just pass it as string parameter to newText

Hi Piotrz55,

I saved the file as you mention in utf8 format using windows notepad but still i am not able to show Arabic numbers displayed. I don’t want to use the Arabic numbers in the code. I want to send it as text only if possible. 

the issue when i type “1” … it comes as English only… where as the Arabic letter comes perfectly in the screen… the issue in the numbers only.

any idea  ???

Regards

Abdul

When you type “1” then it english one not arabic! You must pass arabic character for one - as one-character string.

I suggest you to use notepad++ at least and change file encoding to utf8(without BOM). Then save it.

Hi Piotrz55,

I appreciate your quick response. I tried doing that but I was not able to type  Arabic numbers within the file nor in the notepad for testing. I found something interesting , when I change the settings for regional settings in the control panel to set the " use native digits"  = National.. every number in my  PC changed to Arabic… even inside lua code. when I run the lua file i got Arabic numbers also displayed.  This works but not the way I want it because I don’t want the Arabic number to show in the code because it is confusing, 

I don’t what else I can do in this issue. but i am successful to do it in notepad then i am sure it will work within lua file…

Regards

Abdulaziz

I tried doing that but I was not able to type  Arabic numbers  within the file nor in the notepad for testing

You cannot type arabic characters in editors (only english and ones your keyboard supports).  First you must translate some text and then paste it into string in your code.

Just to clarify ,., i am able to type Arabic words within display.newtext and it works perfectly in the phone or simulator… the issue with numbers only.. I think the numbers needs to manged differently if you want to display them in different language other than English.

the default is always English numbers even i am typing Arabic language … !!!

please see the picture that shows the issue :

arabic_numbers.png

Ah, didn’t know you have keyboard supporting arabic characters. So if your keyboard or editor supports only “1” (as used in english but generaly speaking: 1, 2, 3, 4, 5,… are called “arabic numerals” :smiley: ) then only some copy-paste from external source will do for numbers in string format  :)

:)  :)  :slight_smile:

it didn’t work… i copied the  Arabic number  from MS Word ( in MS word called Hindi)… ar_numbers.png but when i paste in outlaw it showed as English …  outlaw_paste.png

My friend . I think this something might be new for Corona SDK as i don’t see Arabic developers yet… this might come to corona sooner or later…

My app is like a game for kids to select letters and get some  credit… at the end i want to show them the number of how much they got. At the same time i want to show it in Arabic format ( some people called it Hindi like in MS word )…

Even if string works then it will not help me much… for even string is not working… if at least string works then we might think to format the result number and do some tricks to show it in Arabic  :(  :(  :(  :(  :frowning:

I don’t know what is the cuase but this may be a workaround: http://developer.coronalabs.com/code/utf-8-encode-and-decode

First go to http://www.cafewebmaster.com/online_tools/utf8_encode

Copy some arabic numbers to the form and choose UTF-8 encode.

Take the result and put in newText

[lua]

local test = display.newText(utf8_decode(“Ù¡â - Ù¢â - Ù£â - Ù¤â - Ù¥â - Ù¦â - Ù§â”), 0, 0, native.systemFont, 10)

[/lua]

And you should see arabic numbers. 

jon,

i will try to make what you suggest and i see if i can make… also i found the below link which explain something similar but in Java…

please have a look

http://stackoverflow.com/questions/1675786/convert-from-english-digits-to-arabic-ones-in-html-page/1675965#1675965

Perfect , 

I am able to display number 11 in Arabic using the following :

[lua]

local test = display.newText(utf8_decode(“١١”), 0, 0, native.systemFont, 55)

[/lua]

Now how can I convert the calculated value let us say result in Arabic coding and then use the above function to display it.

for example :

result = 200 

ar_number_2.png

Try this (requires the utf8_decode function)

[lua]

local function numbersToArabic(numberString)

        

        local numberString = tostring(numberString)

        local replacements = {[“1”] = “Ù¡”, [“2”] = “etc”, [“3”] = “etc”}

        return utf8_decode(string.gsub (numberString, “%d”, function (str) return replacements [str] or str end))

        

 end

    

print(numbersToArabic(“You scored 11”))

[/lua]

You have to add to the replacements table of course.

Jon,

Thanks Man for your help , it works using the following

[lua]
local function numbersToArabic(numberString)
       
        local numberString = tostring(numberString)
        local replacements = {[“0”] = "Ù ",[“1”] = “Ù¡”, [“2”] = “Ù¢”, [“3”] = “Ù£”,[“4”] = “Ù¤”,[“5”] = “Ù¥”,[“6”] = “Ù¦”,[“7”] = “Ù§”,[“8”] = “Ù¨”,[“9”] = “Ù©”}
        return utf8_decode(string.gsub (numberString, “%d”, function (str) return replacements [str] or str end))
       
end


ToArabicNum=numbersToArabic(“0123456789”)
local test = display.newText(ToArabicNum, 0, 0, native.systemFont, 55)
[/lua]

I have one question just to understand the concept for the conversion. What is the difference between the coding we used from the website you provided (http://www.cafewebmaster.com/online_tools/utf8_encode ) and the one I found (http://www.utf8-chartable.de/unicode-utf8-table.pl).

in your website number 1 in arabic is encoding as “Ù¡”    whereas in the second website it is encoded as “U+0661” see the picture below for arabic encoding , when i used these encodes with functions you prvoided it didnt work…
 

" Ù¡" and such is probably because editor or editor’s font do not support this unicode characters (if it would you would see arabic ones) and tries to somehow display this character using other knows signs.

Ù¡  is how your editor reads what in unicode table is stated as  U+0661  but when you write  U+0661 manualy then it doesn’t interpret it as unicode character. 

You just have to stick to your method :slight_smile:

Thanks Both Jon and piotrz55,

I appreciate your responses and explanation until we read to the solution. I am still wishing to see more explanation in this topic or similar ones because it will really help many people who use different languages… Also I marked this as solved ., :slight_smile:

Regards

Abdulaziz

If your file is saved in utf8 format (without BOM) and your font supports arabic characters then you can just pass string with arabic text to display.newText