|
2 | 2 | * Internationalization service for handling translations and locale-specific formatting |
3 | 3 | * Follows the Singleton pattern to ensure consistent language across the application |
4 | 4 | */ |
| 5 | + |
| 6 | +// Define a custom type for our named format options |
| 7 | +interface DateFormatOptions { |
| 8 | + short: Intl.DateTimeFormatOptions; |
| 9 | + medium: Intl.DateTimeFormatOptions; |
| 10 | + long: Intl.DateTimeFormatOptions; |
| 11 | + full: Intl.DateTimeFormatOptions; |
| 12 | + [key: string]: Intl.DateTimeFormatOptions; |
| 13 | +} |
| 14 | + |
5 | 15 | export class InternationalizationService { |
6 | 16 | private static instance: InternationalizationService; |
7 | 17 | private _locale: string; |
8 | 18 | private _translations: Record<string, Record<string, string>> = {}; |
9 | | - private _dateTimeFormats: Record<string, Intl.DateTimeFormatOptions> = {}; |
| 19 | + private _dateTimeFormats: Record<string, DateFormatOptions> = {}; |
10 | 20 |
|
11 | 21 | /** |
12 | 22 | * Private constructor to enforce the Singleton pattern |
@@ -138,7 +148,7 @@ export class InternationalizationService { |
138 | 148 | */ |
139 | 149 | public setDateTimeFormat(locale: string, formatName: string, formatOptions: Intl.DateTimeFormatOptions): void { |
140 | 150 | if (!this._dateTimeFormats[locale]) { |
141 | | - this._dateTimeFormats[locale] = {}; |
| 151 | + this._dateTimeFormats[locale] = {} as DateFormatOptions; |
142 | 152 | } |
143 | 153 | this._dateTimeFormats[locale][formatName] = formatOptions; |
144 | 154 | } |
|
0 commit comments