I am using the following JavaScript to convert all the English numbers showing on my website to Persian.
I realize that there are several ways to go about this and I have looked online and tried a few, however, this script does what I want it to do and it was really easy to implement except I want the phone number and date in my footer to be excluded from the conversion and remain English.
Not sure how I go about this in my PHP/HTML page.
On the second note, when my site is loading for a couple of seconds the numbers appear in English and quickly convert to Persian. Just wondering if there was a way that I could reduce this delay?
Here is my code:
<script language="JavaScript" type="text/javascript">
var replaceDigits = function() {
var map =
[
"&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;",
"&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"
]
document.body.innerHTML =
document.body.innerHTML.replace(
/\d(?=[^<>]*(<|$))/g,
function($0) { return map[$0] }
);
}
</script>
<script type="text/javascript">
window.onload = replaceDigits
</script>