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


<td id="prev" colspan="৩">
   <a title="View posts for অক্টোবর ২০১৩" href="http://localhost/wp_developer/?m=২০১৩১০">
      « অক্টোবর

So there are two problems:

  1. The anchor is getting wrong path so the archive URL is not isset (?m=২০১৩১০)
  2. 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.



Assuming you mean the default calendar widget, you really have two choices:

  1. Wildly complicated regex
  2. Or make your own widget.

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.

  • Can't we exclude the inner numbers of HTML tags, using any skip attribute (I have no idea what that can be...) into here: $converted = str_replace($engNumber, $bangNumber, $str); - if so, then we can solve the problem very easily. – Mayeenul Islam Nov 4 '13 at 4:47
  • @MayeenulIslam: that option did not occur to me but is seems pretty prone to error on the face of it. – s_ha_dum Nov 4 '13 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.