Overview
app-datepicker uses the nativeIntl.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 thelocale property to any valid BCP 47 language tag:
Auto-Detection
If no locale is specified, the component automatically uses the browser’s locale:- Lit Template
- JavaScript
- HTML Attribute
Date Format Examples
The locale affects how dates are displayed throughout the component:Internal Formatters
The component creates multipleIntl.DateTimeFormat instances for different parts of the UI. Here’s how they’re configured:
View formatter implementation
View formatter implementation
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:- Sunday Start
- Monday Start
- Saturday Start
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:Navigation Labels
View default label constants
View default label constants
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:View default clear label
View default clear 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:View locale test example
View locale test example
From
src/__tests__/date-picker/app-date-picker.test.ts:109-141:Best Practices
Next Steps
Styling
Customize the visual appearance of the date picker
Advanced Features
Configure week numbers, disabled dates, and more