Skip to main content

Overview

app-datepicker uses the native Intl.DateTimeFormat API for internationalization, providing automatic localization for over 100 locales without requiring additional language packs.
The component leverages the browser’s built-in internationalization capabilities, ensuring consistent formatting across your application.

Setting the Locale

Basic Locale Configuration

Set the locale property to any valid BCP 47 language tag:

Auto-Detection

If no locale is specified, the component automatically uses the browser’s locale:

Date Format Examples

The locale affects how dates are displayed throughout the component:

Internal Formatters

The component creates multiple Intl.DateTimeFormat instances for different parts of the UI. Here’s how they’re configured:
From src/helpers/to-formatters.ts:6-42:

Formatter Types

The component uses these formatters internally:

First Day of Week

Customize which day starts the week:
The value is 0 for Sunday through 6 for Saturday, matching JavaScript’s Date.getDay() convention.

Customizing Labels

Override default UI labels for complete localization:
From src/constants.ts:6-14:

Date Labels

Week Number Labels

Complete Localization Example

Here’s a fully localized French date picker:

Localization with Dialog

The dialog component includes additional labels for action buttons:

Localization with Input

The input component includes a clear button label:
From src/date-picker-input/constants.ts:3:

Dynamic Locale Switching

Change locale dynamically at runtime:

Testing Localization

Here’s an example from the test suite showing locale behavior:
From src/__tests__/date-picker/app-date-picker.test.ts:109-141:

Best Practices

Always specify locale explicitly for consistent behavior across different browsers and user settings.
Match firstDayOfWeek to locale conventions for the best user experience (e.g., Monday for European locales).
Changing the locale after component initialization will re-render the calendar. Avoid frequent locale changes for better performance.

Next Steps

Styling

Customize the visual appearance of the date picker

Advanced Features

Configure week numbers, disabled dates, and more