==== Calendar Widget ====
=== Consistent Day Name Abbreviation ===
This guide explains how to generate and display localized day names in the Calendar widget, ensuring consistent abbreviations across different locales (e.g., German, Japanese). The key idea is to always fetch the full day name with '' '%A' '' and then truncate it to the desired length using ''$day_name_length''.
=== Why Not '%a'? ===
* '''%a' '' returns system-defined short names (e.g., "Mo"/"Di" in German or "月曜"/"火曜" in Japanese), which can vary by environment and length.
* Using '' '%A' '' ensures you always start with the full name (e.g., "Montag", "Dienstag", "月曜日", "火曜日"). Truncating with mb_substr gives you precise control over abbreviation length.
=== Implementation Steps ===
1. Fetch full day names
// Initialize day names array
$day_names = array();
for ($n = 0, $t = (3 + $first_day) * 86400; $n < 7; $n++, $t += 86400) {
// '%A' always returns the full day name in current locale
$day_names[$n] = ucfirst(date_strformat('%A', $t));
}
2. Output with controlled abbreviation
// Output table headers for weekdays
foreach ($day_names as $fullName) {
// Truncate to $day_name_length characters
if ($day_name_length > 0) {
$label = mb_substr($fullName, 0, $day_name_length, $characterset);
} else {
// 0 means show full name
$label = $fullName;
}
// Use the full name for the 'abbr' attribute
$calendar .= '| '
.htmlentities($label).' | ';
}
3. Adjust ''$day_name_length''
* 3 → Three-character labels: e.g., "Mon", "Die", "水曜"
* 1 → Single-character labels: e.g., "M", "D", "火"
* 0 → Full names: e.g., "Monday", "Dienstag", "月曜日"
=== Examples ===
**German (locale="de-de", $day_name_length = 3):**
* Full: Montag, Dienstag
* Truncated: Mon, Die
**Japanese (locale="ja-jp", $day_name_length = 1):**
* Full: 月曜日, 火曜日
* Truncated: 月, 火
=== Benefits ===
* Consistency: Always truncates to exactly ''$day_name_length'' characters, regardless of locale.
* Control: You decide the abbreviation scheme rather than relying on system defaults.
* Accessibility: The full name remains in the abbr attribute for screen readers and tooltips.
=== Integration ===
Ensure ''$characterset'' matches your locale encoding and that ''set_locale()'' is called appropriately.