|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import { localize } from '../../nls.js'; |
| 7 | +import { Lazy } from './lazy.js'; |
7 | 8 | import { LANGUAGE_DEFAULT } from './platform.js'; |
8 | 9 |
|
9 | 10 | const minute = 60; |
@@ -264,32 +265,49 @@ export function toLocalISOString(date: Date): string { |
264 | 265 | } |
265 | 266 |
|
266 | 267 | export const safeIntl = { |
267 | | - DateTimeFormat(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat { |
268 | | - try { |
269 | | - return new Intl.DateTimeFormat(locales, options); |
270 | | - } catch { |
271 | | - return new Intl.DateTimeFormat(undefined, options); |
272 | | - } |
| 268 | + DateTimeFormat(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): Lazy<Intl.DateTimeFormat> { |
| 269 | + return new Lazy(() => { |
| 270 | + try { |
| 271 | + return new Intl.DateTimeFormat(locales, options); |
| 272 | + } catch { |
| 273 | + return new Intl.DateTimeFormat(undefined, options); |
| 274 | + } |
| 275 | + }); |
273 | 276 | }, |
274 | | - Collator(locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): Intl.Collator { |
275 | | - try { |
276 | | - return new Intl.Collator(locales, options); |
277 | | - } catch { |
278 | | - return new Intl.Collator(undefined, options); |
279 | | - } |
| 277 | + Collator(locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): Lazy<Intl.Collator> { |
| 278 | + return new Lazy(() => { |
| 279 | + try { |
| 280 | + return new Intl.Collator(locales, options); |
| 281 | + } catch { |
| 282 | + return new Intl.Collator(undefined, options); |
| 283 | + } |
| 284 | + }); |
280 | 285 | }, |
281 | | - Segmenter(locales?: Intl.LocalesArgument, options?: Intl.SegmenterOptions): Intl.Segmenter { |
282 | | - try { |
283 | | - return new Intl.Segmenter(locales, options); |
284 | | - } catch { |
285 | | - return new Intl.Segmenter(undefined, options); |
286 | | - } |
| 286 | + Segmenter(locales?: Intl.LocalesArgument, options?: Intl.SegmenterOptions): Lazy<Intl.Segmenter> { |
| 287 | + return new Lazy(() => { |
| 288 | + try { |
| 289 | + return new Intl.Segmenter(locales, options); |
| 290 | + } catch { |
| 291 | + return new Intl.Segmenter(undefined, options); |
| 292 | + } |
| 293 | + }); |
287 | 294 | }, |
288 | | - Locale(tag: Intl.Locale | string, options?: Intl.LocaleOptions): Intl.Locale { |
289 | | - try { |
290 | | - return new Intl.Locale(tag, options); |
291 | | - } catch { |
292 | | - return new Intl.Locale(LANGUAGE_DEFAULT, options); |
293 | | - } |
| 295 | + Locale(tag: Intl.Locale | string, options?: Intl.LocaleOptions): Lazy<Intl.Locale> { |
| 296 | + return new Lazy(() => { |
| 297 | + try { |
| 298 | + return new Intl.Locale(tag, options); |
| 299 | + } catch { |
| 300 | + return new Intl.Locale(LANGUAGE_DEFAULT, options); |
| 301 | + } |
| 302 | + }); |
| 303 | + }, |
| 304 | + NumberFormat(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): Lazy<Intl.NumberFormat> { |
| 305 | + return new Lazy(() => { |
| 306 | + try { |
| 307 | + return new Intl.NumberFormat(locales, options); |
| 308 | + } catch { |
| 309 | + return new Intl.NumberFormat(undefined, options); |
| 310 | + } |
| 311 | + }); |
294 | 312 | } |
295 | 313 | }; |
0 commit comments