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:
parent
6f79954342
commit
8ca49037e9
4 changed files with 31 additions and 22 deletions
|
|
@ -546,6 +546,13 @@ export class CalendarConfig {
|
||||||
return this.timeFormatConfig.timezone;
|
return this.timeFormatConfig.timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configured locale
|
||||||
|
*/
|
||||||
|
getLocale(): string {
|
||||||
|
return this.timeFormatConfig.locale;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if using 24-hour format
|
* Check if using 24-hour format
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,16 @@ export class DateHeaderRenderer implements HeaderRenderer {
|
||||||
|
|
||||||
render(calendarHeader: HTMLElement, context: HeaderRenderContext): void {
|
render(calendarHeader: HTMLElement, context: HeaderRenderContext): void {
|
||||||
const { currentWeek, config } = context;
|
const { currentWeek, config } = context;
|
||||||
|
|
||||||
// FIRST: Always create all-day container as part of standard header structure
|
// FIRST: Always create all-day container as part of standard header structure
|
||||||
const allDayContainer = document.createElement('swp-allday-container');
|
const allDayContainer = document.createElement('swp-allday-container');
|
||||||
calendarHeader.appendChild(allDayContainer);
|
calendarHeader.appendChild(allDayContainer);
|
||||||
|
|
||||||
// Initialize date service with config
|
// Initialize date service with timezone and locale from config
|
||||||
const timezone = config.getTimezone?.() || 'Europe/Copenhagen';
|
const timezone = config.getTimezone?.() || 'Europe/Copenhagen';
|
||||||
|
const locale = config.getLocale?.() || 'da-DK';
|
||||||
this.dateService = new DateService(timezone);
|
this.dateService = new DateService(timezone);
|
||||||
|
|
||||||
const workWeekSettings = config.getWorkWeekSettings();
|
const workWeekSettings = config.getWorkWeekSettings();
|
||||||
const dates = this.dateService.getWorkWeekDates(currentWeek, workWeekSettings.workDays);
|
const dates = this.dateService.getWorkWeekDates(currentWeek, workWeekSettings.workDays);
|
||||||
const weekDays = config.getDateViewSettings().weekDays;
|
const weekDays = config.getDateViewSettings().weekDays;
|
||||||
|
|
@ -48,15 +49,15 @@ export class DateHeaderRenderer implements HeaderRenderer {
|
||||||
if (this.dateService.isSameDay(date, new Date())) {
|
if (this.dateService.isSameDay(date, new Date())) {
|
||||||
(header as any).dataset.today = 'true';
|
(header as any).dataset.today = 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
const dayName = this.dateService.getDayName(date, 'short');
|
const dayName = this.dateService.getDayName(date, 'long', locale).toUpperCase();
|
||||||
|
|
||||||
header.innerHTML = `
|
header.innerHTML = `
|
||||||
<swp-day-name>${dayName}</swp-day-name>
|
<swp-day-name>${dayName}</swp-day-name>
|
||||||
<swp-day-date>${date.getDate()}</swp-day-date>
|
<swp-day-date>${date.getDate()}</swp-day-date>
|
||||||
`;
|
`;
|
||||||
(header as any).dataset.date = this.dateService.formatISODate(date);
|
(header as any).dataset.date = this.dateService.formatISODate(date);
|
||||||
|
|
||||||
calendarHeader.appendChild(header);
|
calendarHeader.appendChild(header);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,10 +139,11 @@ export class DateService {
|
||||||
* Get day name for a date
|
* Get day name for a date
|
||||||
* @param date - Date to get day name for
|
* @param date - Date to get day name for
|
||||||
* @param format - 'short' (e.g., 'Mon') or 'long' (e.g., 'Monday')
|
* @param format - 'short' (e.g., 'Mon') or 'long' (e.g., 'Monday')
|
||||||
|
* @param locale - Locale for day name (default: 'da-DK')
|
||||||
* @returns Day name
|
* @returns Day name
|
||||||
*/
|
*/
|
||||||
public getDayName(date: Date, format: 'short' | 'long' = 'short'): string {
|
public getDayName(date: Date, format: 'short' | 'long' = 'short', locale: string = 'da-DK'): string {
|
||||||
const formatter = new Intl.DateTimeFormat('en-US', {
|
const formatter = new Intl.DateTimeFormat(locale, {
|
||||||
weekday: format
|
weekday: format
|
||||||
});
|
});
|
||||||
return formatter.format(date);
|
return formatter.format(date);
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ swp-day-header {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding-top: 7px;
|
padding-top: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
swp-day-header:last-child {
|
swp-day-header:last-child {
|
||||||
|
|
@ -299,27 +299,27 @@ swp-day-name {
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--color-text-secondary);
|
color: var(--color-text-secondary);
|
||||||
|
letter-spacing: 0.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
swp-day-date {
|
swp-day-date {
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 20px;
|
font-size: 30px;
|
||||||
font-weight: 600;
|
|
||||||
margin-top: 4px;
|
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 {
|
swp-day-header[data-today="true"] swp-day-date {
|
||||||
color: var(--color-primary);
|
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 */
|
/* Ghost columns for mouseenter events */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue