I collected a good numerals replacing function for WordPress calendar:
function make_bangla_number($str)
{
$engNumber = array('0','1','2','3','4','5','6','7','8','9');
$bangNumber = array('০','১','২','৩','৪','৫','৬','à§','৮','৯');
$converted = str_replace($engNumber, $bangNumber, $str);
return $converted;
}
The function clearly stating that, it’s taking English numerals and just replacing them with BÄnglÄ numerals.
But the problem is with a similar function I can replace all the Gregorian Months to BÄnglÄ scripts, but using the numerals function, I’m messing the calendar widget. Because calling:
add_filter( 'get_calendar', 'make_bangla_number' );
replaces all the numerals, even in the HTML. Suppose the previous month link in HTML:
<td id="prev" colspan="3">
<a title="View posts for October 2013" href="http://localhost/wp_developer/?m=201310">
« Oct
</a>
</td>
getting…
<td id="prev" colspan="৩">
<a title="View posts for à¦
à¦à§à¦à§à¦¬à¦° ২০১৩" href="http://localhost/wp_developer/?m=২০১৩১০">
« à¦
à¦à§à¦à§à¦¬à¦°
</a>
</td>
So there are two problems:
- The anchor is getting wrong path so the archive URL is not isset (
?m=২০১৩১০
) - The structure of Widget archive is breaking, because the HTML is getting wrong value for HTML properties (
colspan="৩"
)
And you all know that all the Unicode numerals can be equal in Numerical value, but not equal to their Binary value. So the Latin Numeral 1
is not equivalent to BÄnglÄ Numeral ১
in compare to their Binary value.
So,
HOW CAN WE PROCEED WITH SUCH A FILTER/HOOK IN A SAFE WAY?
Assuming you mean the default calendar widget, you really have two choices:
I would opt for #2, the meat of which is actually the
get_calendar
function. Clone that function and alter the dates as you need to.This is assuming that there is no proper localized version of WordPress for your language– see @birgire’s comment.