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)?
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.