1

I have this function

var map =
[
"&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
"&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
];

function getArabicNumbers(str)
{
    var newStr = "";

    str = String(str);

    for(i=0; i<str.length; i++)
    {
        newStr += map[parseInt(str.charAt(i))];
    }

    return newStr;
}

which is taken from How can I view Arabic/Persian numbers in a HTML page with strict doctype?

This function will only work if you put something between the parenthesis in getArabicNumbers() when you call out for it.

I want to apply this function on the document from its beginning to its end! how can I do that? Is it possible in javascript? do you recommend it?

any other way to replace English numbers to Arabic numbers using javascript (on the full page not on a string)?

Community
  • 1
  • 1
syrkull
  • 2,295
  • 4
  • 35
  • 68
  • Why would you want that? Can't you provide the arabic numbers serverside? – Bergi Jul 05 '12 at 00:22
  • arabic is not supported by the servers. also, there is some html writings here and there that contains some numbers which I want to convert to Arabic. and If I replaced the english number do arabic number manually, then search engines will not recognize them as numbers and will not index them (I have read somebody saying that in here) – syrkull Jul 05 '12 at 00:30

1 Answers1

5

You need to walk the DOM tree and for each textnode call replace with the getArabicNumbers.

I would change the getArabicNumbers function to a regex probably; all you need to do is match 0-9 and then map it using a callback.

Edit: Here's a little fiddle I put together for the fun of it and to demonstrate what I'm talking about and it seems to work perfectly although I am a little unsure about the Right-To-Left part...

Edit2: D'oh... You can even do without the map[] array.

RobIII
  • 8,488
  • 2
  • 43
  • 93