Improves date header localization

Adds locale support to the date header renderer and date service.

This change ensures that the day names are displayed correctly based on the user's configured locale.

The date header now uses the configured locale to display the day name in the correct language.
The day name is now displayed in uppercase.

Additionally, styles the date header to highlight today's date.
This commit is contained in:
Janus C. H. Knudsen 2025-10-09 23:08:33 +02:00
parent 6f79954342
commit 8ca49037e9
4 changed files with 31 additions and 22 deletions

View file

@ -546,6 +546,13 @@ export class CalendarConfig {
return this.timeFormatConfig.timezone;
}
/**
* Get configured locale
*/
getLocale(): string {
return this.timeFormatConfig.locale;
}
/**
* Check if using 24-hour format
*/

View file

@ -34,8 +34,9 @@ export class DateHeaderRenderer implements HeaderRenderer {
const allDayContainer = document.createElement('swp-allday-container');
calendarHeader.appendChild(allDayContainer);
// Initialize date service with config
// Initialize date service with timezone and locale from config
const timezone = config.getTimezone?.() || 'Europe/Copenhagen';
const locale = config.getLocale?.() || 'da-DK';
this.dateService = new DateService(timezone);
const workWeekSettings = config.getWorkWeekSettings();
@ -49,7 +50,7 @@ export class DateHeaderRenderer implements HeaderRenderer {
(header as any).dataset.today = 'true';
}
const dayName = this.dateService.getDayName(date, 'short');
const dayName = this.dateService.getDayName(date, 'long', locale).toUpperCase();
header.innerHTML = `
<swp-day-name>${dayName}</swp-day-name>

View file

@ -139,10 +139,11 @@ export class DateService {
* Get day name for a date
* @param date - Date to get day name for
* @param format - 'short' (e.g., 'Mon') or 'long' (e.g., 'Monday')
* @param locale - Locale for day name (default: 'da-DK')
* @returns Day name
*/
public getDayName(date: Date, format: 'short' | 'long' = 'short'): string {
const formatter = new Intl.DateTimeFormat('en-US', {
public getDayName(date: Date, format: 'short' | 'long' = 'short', locale: string = 'da-DK'): string {
const formatter = new Intl.DateTimeFormat(locale, {
weekday: format
});
return formatter.format(date);

View file

@ -246,7 +246,7 @@ swp-day-header {
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 7px;
padding-top: 3px;
}
swp-day-header:last-child {
@ -299,27 +299,27 @@ swp-day-name {
font-weight: 500;
font-size: 12px;
color: var(--color-text-secondary);
letter-spacing: 0.1em;
}
swp-day-date {
display: block;
font-size: 20px;
font-weight: 600;
font-size: 30px;
margin-top: 4px;
height: 41px;
}
/* Highlight entire header for today */
swp-day-header[data-today="true"] {
background: rgba(33, 150, 243, 0.1);
}
swp-day-header[data-today="true"] swp-day-name {
color: var(--color-primary);
font-weight: 600;
}
swp-day-header[data-today="true"] swp-day-date {
color: var(--color-primary);
background: rgba(33, 150, 243, 0.1);
border-radius: 50%;
width: 41px;
height: 41px;
display: flex;
align-items: center;
justify-content: center;
margin: 4px auto 0;
}
/* Ghost columns for mouseenter events */