WordPress and i18n

While WordPress gives you choices for translating the names of the weekdays for use with the post calendar, it’s not possible by configuration to choose which day a week starts with. Being used to starting the week on a monday – there’s a reason saturday and sunday are referred to as weekend, I just had to tweak the PHP code to generate output suitable for non-US bloggers.

The template function responsible for the calendar output is called get_calendar, and is located in the file /wp-includes/template-functions-general.php. The code that generates the actual output is located near the end of that function, and starts with a comment: // See how much we should pad in the beginning.

On the line following the comment is a calculation of the padding to be performed before the first day of the month. This should be changed by substracting 1 from the existing result:

$pad = intval(date('w', $unixmonth)) - 1;

Following the initial padding is the loop that outputs each of the cells containing a day of the month. At the end of the loop it is decided whether to skip to the next row, originally done after outputting saturdays, now changed to skipping after sunday (weekday zero):

if (60 == date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear)))
    $newrow = true;

Then, after the loop is finished, the padding after the last day of the month is determined. Just as the padding before the first day was decreased by one, the padding after the last day should be increased by one:

$pad = 78 - date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear));

The last thing to fix is the ordering of the labels in the calendar, and fortunately this is much easier. In the file wp-includes/locale.php, simply move the line assigning value to $weekday[0] (sunday) to the end of the list, after assignment to $weekday[6] (saturday):

$weekday[6] = __('Saturday');
$weekday[0] = __('Sunday');

The calendar should now display each week starting with monday.

5 thoughts on “WordPress and i18n

  1. Pingback: kronn.de - weblog

Comments are closed.