How to hook some Unicode texts into calendar widget safely?

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.

Read More

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:

  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.

So,
HOW CAN WE PROCEED WITH SUCH A FILTER/HOOK IN A SAFE WAY?

Related posts

1 comment

  1. 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.

Comments are closed.