Overview
ThemiscI18n component demonstrates how to use Salesforce i18n modules and the JavaScript Intl API to format dates and currencies according to different locales.
Source Component
- miscI18n - Formats dates and currencies using locale settings
Key Features
- Access user’s locale and currency settings
- JavaScript Intl API for formatting
- Date formatting by locale
- Currency formatting with symbols
- No custom labels required
Implementation
Accessing User Settings
Import user locale and currency from Salesforce:Date Formatting
UseIntl.DateTimeFormat to format dates:
Date Format Examples
- en-US: 3/9/2026
- ja-JP: 2026/3/9
- en-GB: 09/03/2026
- de-DE: 9.3.2026
The
Intl.DateTimeFormat API automatically adapts to the locale’s standard date format. You can also customize the format using options like { year: 'numeric', month: 'long', day: 'numeric' }.Currency Formatting
UseIntl.NumberFormat with currency options:
Currency Format Examples
- en-US (USD): $100.00
- ja-JP (JPY): ¥100
- en-GB (GBP): £100.00
- de-DE (EUR): 100,00 €
Available Salesforce i18n Imports
Salesforce provides several i18n modules:Advanced Formatting Options
Custom Date Formats
Number Formatting
Currency Display Options
Template Usage
Display formatted values in your template:Best Practices
- Use Salesforce i18n modules to get user settings
- Leverage the Intl API for consistent formatting
- Test with multiple locales during development
- Avoid hardcoding date and currency formats
- Use getters for formatted values to ensure reactivity
The Intl API is part of the JavaScript standard and works in all modern browsers. It provides more flexibility than custom formatting logic and automatically handles locale-specific rules.
Source Files
force-app/main/default/lwc/miscI18n/
