@mmstack/translate 20.5.11 → 20.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +298 -181
- package/fesm2022/mmstack-translate.mjs +484 -96
- package/fesm2022/mmstack-translate.mjs.map +1 -1
- package/index.d.ts +316 -71
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Signal,
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import { Signal, Provider, WritableSignal } from '@angular/core';
|
|
3
|
+
import * as _mmstack_translate from '@mmstack/translate';
|
|
3
4
|
import { ResolveFn, ActivatedRouteSnapshot, CanMatchFn } from '@angular/router';
|
|
4
5
|
import * as _formatjs_intl from '@formatjs/intl';
|
|
5
6
|
import { IntlConfig } from '@formatjs/intl';
|
|
@@ -90,7 +91,48 @@ type TranslationNamespace<TNS extends string, T extends CompiledTranslation<Unkn
|
|
|
90
91
|
};
|
|
91
92
|
declare function createNamespace<const T extends UnknownStringKeyObject, TNS extends string>(ns: TNS, translation: T): TranslationNamespace<TNS, CompiledTranslation<T, TNS, string>, inferTranslationShape<T>>;
|
|
92
93
|
|
|
93
|
-
declare const FORMAT_PRESETS:
|
|
94
|
+
declare const FORMAT_PRESETS: {
|
|
95
|
+
short: {
|
|
96
|
+
dateStyle: "short";
|
|
97
|
+
timeStyle: "short";
|
|
98
|
+
};
|
|
99
|
+
medium: {
|
|
100
|
+
dateStyle: "medium";
|
|
101
|
+
timeStyle: "medium";
|
|
102
|
+
};
|
|
103
|
+
long: {
|
|
104
|
+
dateStyle: "long";
|
|
105
|
+
timeStyle: "long";
|
|
106
|
+
};
|
|
107
|
+
full: {
|
|
108
|
+
dateStyle: "full";
|
|
109
|
+
timeStyle: "full";
|
|
110
|
+
};
|
|
111
|
+
shortDate: {
|
|
112
|
+
dateStyle: "short";
|
|
113
|
+
};
|
|
114
|
+
mediumDate: {
|
|
115
|
+
dateStyle: "medium";
|
|
116
|
+
};
|
|
117
|
+
longDate: {
|
|
118
|
+
dateStyle: "long";
|
|
119
|
+
};
|
|
120
|
+
fullDate: {
|
|
121
|
+
dateStyle: "full";
|
|
122
|
+
};
|
|
123
|
+
shortTime: {
|
|
124
|
+
timeStyle: "short";
|
|
125
|
+
};
|
|
126
|
+
mediumTime: {
|
|
127
|
+
timeStyle: "medium";
|
|
128
|
+
};
|
|
129
|
+
longTime: {
|
|
130
|
+
timeStyle: "long";
|
|
131
|
+
};
|
|
132
|
+
fullTime: {
|
|
133
|
+
timeStyle: "full";
|
|
134
|
+
};
|
|
135
|
+
};
|
|
94
136
|
type DateFormat = keyof typeof FORMAT_PRESETS;
|
|
95
137
|
/**
|
|
96
138
|
* Supported date inputs
|
|
@@ -108,21 +150,43 @@ type FormatDateOptions = {
|
|
|
108
150
|
* Format to use for formatting
|
|
109
151
|
* @default 'medium'
|
|
110
152
|
*/
|
|
111
|
-
format?: DateFormat;
|
|
153
|
+
format?: DateFormat | Intl.DateTimeFormatOptions;
|
|
112
154
|
/**
|
|
113
|
-
* Locale to use for formatting
|
|
155
|
+
* Locale to use for formatting
|
|
114
156
|
*/
|
|
157
|
+
locale: string;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
161
|
+
*/
|
|
162
|
+
type UnsafeFormatDateOptions = Omit<FormatDateOptions, 'locale'> & {
|
|
163
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
115
164
|
locale?: string;
|
|
116
165
|
};
|
|
117
166
|
/**
|
|
118
|
-
*
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* @
|
|
123
|
-
|
|
167
|
+
* @example formatDate(this.date, this.locale)
|
|
168
|
+
*/
|
|
169
|
+
declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, locale: string | Signal<string>): string;
|
|
170
|
+
/**
|
|
171
|
+
* @example formatDate(this.date, { locale: 'sl-SI', format: 'shortDate' })
|
|
172
|
+
*/
|
|
173
|
+
declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt: FormatDateOptions | Signal<FormatDateOptions>): string;
|
|
174
|
+
/**
|
|
175
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
176
|
+
* Use `injectFormatDate()` instead, or pass locale explicitly.
|
|
177
|
+
* @example formatDate(this.date)
|
|
178
|
+
*/
|
|
179
|
+
declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt?: UnsafeFormatDateOptions | Signal<UnsafeFormatDateOptions>): string;
|
|
180
|
+
declare const provideFormatDateDefaults: (valueOrFn: Omit<Partial<FormatDateOptions>, "locale"> | (() => Omit<Partial<FormatDateOptions>, "locale"> | Signal<Omit<Partial<FormatDateOptions>, "locale">>)) => _angular_core.Provider;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Inject a context-safe date formatting function tied to the current injector.
|
|
184
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
185
|
+
* @example
|
|
186
|
+
* const formatDate = injectFormatDate();
|
|
187
|
+
* readonly displayDate = computed(() => formatDate(this.date()));
|
|
124
188
|
*/
|
|
125
|
-
declare function
|
|
189
|
+
declare function injectFormatDate(): (date: SupportedDateInput | Signal<SupportedDateInput>, optOrLocale?: Partial<FormatDateOptions> | Signal<Partial<FormatDateOptions>> | string | Signal<string>) => string;
|
|
126
190
|
|
|
127
191
|
/**
|
|
128
192
|
* Options for formatting a display name
|
|
@@ -130,24 +194,46 @@ declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput
|
|
|
130
194
|
type FormatDisplayNameOptions = {
|
|
131
195
|
/**
|
|
132
196
|
* The display style for the result set
|
|
197
|
+
* @default 'long'
|
|
133
198
|
*/
|
|
134
|
-
style
|
|
199
|
+
style?: Intl.RelativeTimeFormatStyle;
|
|
135
200
|
/**
|
|
136
|
-
* Locale to use for formatting
|
|
201
|
+
* Locale to use for formatting
|
|
137
202
|
*/
|
|
203
|
+
locale: string;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
207
|
+
*/
|
|
208
|
+
type UnsafeFormatDisplayNameOptions = Omit<FormatDisplayNameOptions, 'locale'> & {
|
|
209
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
138
210
|
locale?: string;
|
|
139
211
|
};
|
|
140
212
|
type SupportedCode = string | null | undefined;
|
|
141
213
|
/**
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
* @
|
|
147
|
-
|
|
148
|
-
|
|
214
|
+
* @example formatDisplayName(this.value, 'region', this.locale)
|
|
215
|
+
*/
|
|
216
|
+
declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, locale: string | Signal<string>): string;
|
|
217
|
+
/**
|
|
218
|
+
* @example formatDisplayName(this.value, 'region', {locale: 'en-US', style: 'long'})
|
|
219
|
+
*/
|
|
220
|
+
declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions>): string;
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
223
|
+
* Use `injectFormatDisplayName()` instead, or pass locale explicitly.
|
|
224
|
+
* @example formatDisplayName(this.value)
|
|
225
|
+
*/
|
|
226
|
+
declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt?: UnsafeFormatDisplayNameOptions | Signal<UnsafeFormatDisplayNameOptions>): string;
|
|
227
|
+
declare const provideFormatDisplayNameDefaults: (valueOrFn: Omit<Partial<FormatDisplayNameOptions>, "locale"> | (() => Omit<Partial<FormatDisplayNameOptions>, "locale"> | Signal<Omit<Partial<FormatDisplayNameOptions>, "locale">>)) => _angular_core.Provider;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Inject a context-safe date formatting function tied to the current injector.
|
|
231
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
232
|
+
* @example
|
|
233
|
+
* const formatDisplayName = injectFormatDisplayName();
|
|
234
|
+
* readonly region = computed(() => formatDisplayName('US', 'region'));
|
|
149
235
|
*/
|
|
150
|
-
declare function
|
|
236
|
+
declare function injectFormatDisplayName(): (value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, localeOrOpt?: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions> | string | Signal<string>) => string;
|
|
151
237
|
|
|
152
238
|
type ListType = 'conjunction' | 'disjunction' | 'unit';
|
|
153
239
|
type ListStyle = 'long' | 'short' | 'narrow';
|
|
@@ -158,26 +244,50 @@ type SupportedListInput = string[] | null | undefined;
|
|
|
158
244
|
type FormatListOptions = {
|
|
159
245
|
/**
|
|
160
246
|
* The type of list to format
|
|
247
|
+
* @default 'conjunction'
|
|
161
248
|
*/
|
|
162
249
|
type?: ListType;
|
|
163
250
|
/**
|
|
164
251
|
* The style of list to format
|
|
252
|
+
* @default 'long'
|
|
165
253
|
*/
|
|
166
254
|
style?: ListStyle;
|
|
167
255
|
/**
|
|
168
|
-
* Locale to use for formatting
|
|
256
|
+
* Locale to use for formatting
|
|
169
257
|
*/
|
|
258
|
+
locale: string;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
262
|
+
*/
|
|
263
|
+
type UnsafeFormatListOptions = Omit<FormatListOptions, 'locale'> & {
|
|
264
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
170
265
|
locale?: string;
|
|
171
266
|
};
|
|
172
267
|
/**
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* @
|
|
178
|
-
|
|
268
|
+
* @example formatList(this.items, this.locale)
|
|
269
|
+
*/
|
|
270
|
+
declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, locale: string | Signal<string>): string;
|
|
271
|
+
/**
|
|
272
|
+
* @example formatList(this.items, { locale: 'sl-SI', type: 'disjunction' })
|
|
273
|
+
*/
|
|
274
|
+
declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt: FormatListOptions | Signal<FormatListOptions>): string;
|
|
275
|
+
/**
|
|
276
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
277
|
+
* Use `injectFormatList()` instead, or pass locale explicitly.
|
|
278
|
+
* @example formatList(this.items)
|
|
179
279
|
*/
|
|
180
|
-
declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt?:
|
|
280
|
+
declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt?: UnsafeFormatListOptions | Signal<UnsafeFormatListOptions>): string;
|
|
281
|
+
declare const provideFormatListDefaults: (valueOrFn: Omit<Partial<FormatListOptions>, "locale"> | (() => Omit<Partial<FormatListOptions>, "locale"> | Signal<Omit<Partial<FormatListOptions>, "locale">>)) => _angular_core.Provider;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Inject a context-safe list formatting function tied to the current injector.
|
|
285
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
286
|
+
* @example
|
|
287
|
+
* const formatList = injectFormatList();
|
|
288
|
+
* readonly displayList = computed(() => formatList(this.items()));
|
|
289
|
+
*/
|
|
290
|
+
declare function injectFormatList(): (value: SupportedListInput | Signal<SupportedListInput>, optOrLocale?: Partial<FormatListOptions> | Signal<Partial<FormatListOptions>> | string | Signal<string>) => string;
|
|
181
291
|
|
|
182
292
|
type NumberNotation = 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
183
293
|
type SupportedNumberValue = number | null | undefined;
|
|
@@ -187,6 +297,7 @@ type SupportedNumberValue = number | null | undefined;
|
|
|
187
297
|
type FormatNumberOptions = {
|
|
188
298
|
/**
|
|
189
299
|
* The notation to use for formatting
|
|
300
|
+
* @default 'standard'
|
|
190
301
|
*/
|
|
191
302
|
notation?: NumberNotation;
|
|
192
303
|
/**
|
|
@@ -199,27 +310,50 @@ type FormatNumberOptions = {
|
|
|
199
310
|
maxFractionDigits?: number;
|
|
200
311
|
/**
|
|
201
312
|
* Whether to use grouping
|
|
313
|
+
* @default true
|
|
202
314
|
*/
|
|
203
315
|
useGrouping?: boolean;
|
|
204
|
-
/**
|
|
205
|
-
* Locale to use for formatting, opts out to dynamic locale changes
|
|
206
|
-
*/
|
|
207
|
-
locale?: string;
|
|
208
316
|
/**
|
|
209
317
|
* If the number is not a valid number, return formatted 0. By default formatter returns an empty string
|
|
210
318
|
* @default false
|
|
211
319
|
*/
|
|
212
320
|
fallbackToZero?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Locale to use for formatting
|
|
323
|
+
*/
|
|
324
|
+
locale: string;
|
|
213
325
|
};
|
|
214
326
|
/**
|
|
215
|
-
*
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
327
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
328
|
+
*/
|
|
329
|
+
type UnsafeFormatNumberOptions = Omit<FormatNumberOptions, 'locale'> & {
|
|
330
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
331
|
+
locale?: string;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* @example formatNumber(this.value, this.locale)
|
|
335
|
+
*/
|
|
336
|
+
declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, locale: string | Signal<string>): string;
|
|
337
|
+
/**
|
|
338
|
+
* @example formatNumber(this.value, { locale: 'de-DE', notation: 'compact' })
|
|
221
339
|
*/
|
|
222
|
-
declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt
|
|
340
|
+
declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt: FormatNumberOptions | Signal<FormatNumberOptions>): string;
|
|
341
|
+
/**
|
|
342
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
343
|
+
* Use `injectFormatNumber()` instead, or pass locale explicitly.
|
|
344
|
+
* @example formatNumber(this.value)
|
|
345
|
+
*/
|
|
346
|
+
declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: UnsafeFormatNumberOptions | Signal<UnsafeFormatNumberOptions>): string;
|
|
347
|
+
declare const provideFormatNumberDefaults: (valueOrFn: Omit<Partial<FormatNumberOptions>, "locale"> | (() => Omit<Partial<FormatNumberOptions>, "locale"> | Signal<Omit<Partial<FormatNumberOptions>, "locale">>)) => _angular_core.Provider;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Inject a context-safe number formatting function tied to the current injector.
|
|
351
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
352
|
+
* @example
|
|
353
|
+
* const formatNumber = injectFormatNumber();
|
|
354
|
+
* readonly display = computed(() => formatNumber(this.value()));
|
|
355
|
+
*/
|
|
356
|
+
declare function injectFormatNumber(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, optOrLocale?: Partial<FormatNumberOptions> | Signal<Partial<FormatNumberOptions>> | string | Signal<string>) => string;
|
|
223
357
|
/**
|
|
224
358
|
* Options for formatting a percentage value
|
|
225
359
|
*/
|
|
@@ -232,42 +366,97 @@ type FormatPercentOptions = {
|
|
|
232
366
|
* Maximum number of fraction digits to use
|
|
233
367
|
*/
|
|
234
368
|
maxFractionDigits?: number;
|
|
235
|
-
/**
|
|
236
|
-
* Locale to use for formatting, opts out to dynamic locale changes
|
|
237
|
-
*/
|
|
238
|
-
locale?: string;
|
|
239
369
|
/**
|
|
240
370
|
* If the number is not a valid number, return formatted 0. By default formatter returns an empty string
|
|
241
371
|
* @default false
|
|
242
372
|
*/
|
|
243
373
|
fallbackToZero?: boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Locale to use for formatting
|
|
376
|
+
*/
|
|
377
|
+
locale: string;
|
|
244
378
|
};
|
|
245
379
|
/**
|
|
246
|
-
*
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
380
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
381
|
+
*/
|
|
382
|
+
type UnsafeFormatPercentOptions = Omit<FormatPercentOptions, 'locale'> & {
|
|
383
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
384
|
+
locale?: string;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* @example formatPercent(this.value, this.locale)
|
|
252
388
|
*/
|
|
253
|
-
declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>,
|
|
389
|
+
declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, locale: string | Signal<string>): string;
|
|
390
|
+
/**
|
|
391
|
+
* @example formatPercent(this.value, { locale: 'de-DE', maxFractionDigits: 2 })
|
|
392
|
+
*/
|
|
393
|
+
declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt: FormatPercentOptions | Signal<FormatPercentOptions>): string;
|
|
394
|
+
/**
|
|
395
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
396
|
+
* Use `injectFormatPercent()` instead, or pass locale explicitly.
|
|
397
|
+
* @example formatPercent(this.value)
|
|
398
|
+
*/
|
|
399
|
+
declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: UnsafeFormatPercentOptions | Signal<UnsafeFormatPercentOptions>): string;
|
|
400
|
+
declare const provideFormatPercentDefaults: (valueOrFn: Omit<Partial<FormatPercentOptions>, "locale"> | (() => Omit<Partial<FormatPercentOptions>, "locale"> | Signal<Omit<Partial<FormatPercentOptions>, "locale">>)) => _angular_core.Provider;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Inject a context-safe percent formatting function tied to the current injector.
|
|
404
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
405
|
+
*/
|
|
406
|
+
declare function injectFormatPercent(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, optOrLocale?: Partial<FormatPercentOptions> | Signal<Partial<FormatPercentOptions>> | string | Signal<string>) => string;
|
|
254
407
|
type CurrencyDisplay = 'symbol' | 'narrowSymbol' | 'code' | 'name';
|
|
255
408
|
/**
|
|
256
409
|
* Options for formatting a currency
|
|
257
410
|
*/
|
|
258
411
|
type FormatCurrencyOptions = {
|
|
259
|
-
display?: CurrencyDisplay;
|
|
260
412
|
/**
|
|
261
|
-
*
|
|
413
|
+
* The display type for the currency format
|
|
414
|
+
* @default 'symbol'
|
|
262
415
|
*/
|
|
263
|
-
|
|
416
|
+
display?: CurrencyDisplay;
|
|
264
417
|
/**
|
|
265
418
|
* If the number is not a valid number, return formatted 0. By default formatter returns an empty string
|
|
266
419
|
* @default false
|
|
267
420
|
*/
|
|
268
421
|
fallbackToZero?: boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Locale to use for formatting
|
|
424
|
+
*/
|
|
425
|
+
locale: string;
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
429
|
+
*/
|
|
430
|
+
type UnsafeFormatCurrencyOptions = Omit<FormatCurrencyOptions, 'locale'> & {
|
|
431
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
432
|
+
locale?: string;
|
|
269
433
|
};
|
|
270
|
-
|
|
434
|
+
/**
|
|
435
|
+
* @example formatCurrency(this.value, 'USD', this.locale)
|
|
436
|
+
*/
|
|
437
|
+
declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, locale: string | Signal<string>): string;
|
|
438
|
+
/**
|
|
439
|
+
* @example formatCurrency(this.value, 'EUR', { locale: 'de-DE', display: 'code' })
|
|
440
|
+
*/
|
|
441
|
+
declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt: FormatCurrencyOptions | Signal<FormatCurrencyOptions>): string;
|
|
442
|
+
/**
|
|
443
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
444
|
+
* Use `injectFormatCurrency()` instead, or pass locale explicitly.
|
|
445
|
+
* @example formatCurrency(this.value, 'USD')
|
|
446
|
+
*/
|
|
447
|
+
declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt?: UnsafeFormatCurrencyOptions | Signal<UnsafeFormatCurrencyOptions>): string;
|
|
448
|
+
declare const provideFormatCurrencyDefaults: (valueOrFn: Omit<Partial<FormatCurrencyOptions>, "locale"> | (() => Omit<Partial<FormatCurrencyOptions>, "locale"> | Signal<Omit<Partial<FormatCurrencyOptions>, "locale">>)) => _angular_core.Provider;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Inject a context-safe currency formatting function tied to the current injector.
|
|
452
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
453
|
+
*/
|
|
454
|
+
declare function injectFormatCurrency(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, optOrLocale?: Partial<FormatCurrencyOptions> | Signal<Partial<FormatCurrencyOptions>> | string | Signal<string>) => string;
|
|
455
|
+
|
|
456
|
+
declare function createFormatterProvider<T extends {
|
|
457
|
+
locale: string;
|
|
458
|
+
}>(formatterName: string, libraryDefaults: Omit<T, 'locale'>, nonLocaleEqual: (a: Omit<T, 'locale'>, b: Omit<T, 'locale'>) => boolean): readonly [(valueOrFn: Omit<Partial<T>, "locale"> | (() => Omit<Partial<T>, "locale"> | Signal<Omit<Partial<T>, "locale">>)) => Provider, () => Signal<T>];
|
|
459
|
+
type inferProvideParameter<T extends ReturnType<typeof createFormatterProvider>[0]> = Parameters<T>[0];
|
|
271
460
|
|
|
272
461
|
/**
|
|
273
462
|
* Options for formatting a relative time value
|
|
@@ -284,22 +473,63 @@ type FormatRelativeTimeOptions = {
|
|
|
284
473
|
*/
|
|
285
474
|
numeric?: Intl.RelativeTimeFormatNumeric;
|
|
286
475
|
/**
|
|
287
|
-
* Locale to use for formatting
|
|
476
|
+
* Locale to use for formatting
|
|
288
477
|
*/
|
|
478
|
+
locale: string;
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
482
|
+
*/
|
|
483
|
+
type UnsafeFormatRelativeTimeOptions = Omit<FormatRelativeTimeOptions, 'locale'> & {
|
|
484
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
289
485
|
locale?: string;
|
|
290
486
|
};
|
|
291
487
|
type RelativeTimeUnit = Intl.RelativeTimeFormatUnit;
|
|
292
488
|
type SupportedRelativeTimeInput = number | null | undefined;
|
|
293
489
|
/**
|
|
294
|
-
*
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
* @
|
|
299
|
-
* @param opt - Options for formatting
|
|
300
|
-
* @returns Formatted relative time string
|
|
490
|
+
* @example formatRelativeTime(this.value, this.unit, this.locale)
|
|
491
|
+
*/
|
|
492
|
+
declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, locale: string | Signal<string>): string;
|
|
493
|
+
/**
|
|
494
|
+
* @example formatRelativeTime(this.value, 'day', { locale: 'sl-SI', numeric: 'auto' })
|
|
301
495
|
*/
|
|
302
|
-
declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt
|
|
496
|
+
declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt: FormatRelativeTimeOptions | Signal<FormatRelativeTimeOptions>): string;
|
|
497
|
+
/**
|
|
498
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
499
|
+
* Use `injectFormatRelativeTime()` instead, or pass locale explicitly.
|
|
500
|
+
* @example formatRelativeTime(this.value, 'day')
|
|
501
|
+
*/
|
|
502
|
+
declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt?: UnsafeFormatRelativeTimeOptions | Signal<UnsafeFormatRelativeTimeOptions>): string;
|
|
503
|
+
declare const provideFormatRelativeTimeDefaults: (valueOrFn: Omit<Partial<FormatRelativeTimeOptions>, "locale"> | (() => Omit<Partial<FormatRelativeTimeOptions>, "locale"> | Signal<Omit<Partial<FormatRelativeTimeOptions>, "locale">>)) => _angular_core.Provider;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Inject a context-safe relative time formatting function tied to the current injector.
|
|
507
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
508
|
+
* @example
|
|
509
|
+
* const formatRelativeTime = injectFormatRelativeTime();
|
|
510
|
+
* readonly relativeAge = computed(() => formatRelativeTime(this.delta(), 'day'));
|
|
511
|
+
*/
|
|
512
|
+
declare function injectFormatRelativeTime(): (value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, optOrLocale?: Partial<FormatRelativeTimeOptions> | Signal<Partial<FormatRelativeTimeOptions>> | string | Signal<string>) => string;
|
|
513
|
+
|
|
514
|
+
type FormatDefaults = {
|
|
515
|
+
date?: inferProvideParameter<typeof provideFormatDateDefaults>;
|
|
516
|
+
displayName?: inferProvideParameter<typeof provideFormatDisplayNameDefaults>;
|
|
517
|
+
list?: inferProvideParameter<typeof provideFormatListDefaults>;
|
|
518
|
+
relativeTime?: inferProvideParameter<typeof provideFormatRelativeTimeDefaults>;
|
|
519
|
+
number?: inferProvideParameter<typeof provideFormatNumberDefaults>;
|
|
520
|
+
percent?: inferProvideParameter<typeof provideFormatPercentDefaults>;
|
|
521
|
+
currency?: inferProvideParameter<typeof provideFormatCurrencyDefaults>;
|
|
522
|
+
};
|
|
523
|
+
declare function provideFormatDefaults(cfg: FormatDefaults): Provider[];
|
|
524
|
+
declare function injectFormatters(): {
|
|
525
|
+
date: (date: _mmstack_translate.SupportedDateInput | _angular_core.Signal<_mmstack_translate.SupportedDateInput>, optOrLocale?: Partial<_mmstack_translate.FormatDateOptions> | _angular_core.Signal<Partial<_mmstack_translate.FormatDateOptions>> | string | _angular_core.Signal<string>) => string;
|
|
526
|
+
displayName: (value: (string | null | undefined) | _angular_core.Signal<string | null | undefined>, type: Intl.DisplayNamesType | _angular_core.Signal<Intl.DisplayNamesType>, localeOrOpt?: _mmstack_translate.FormatDisplayNameOptions | _angular_core.Signal<_mmstack_translate.FormatDisplayNameOptions> | string | _angular_core.Signal<string>) => string;
|
|
527
|
+
list: (value: _mmstack_translate.SupportedListInput | _angular_core.Signal<_mmstack_translate.SupportedListInput>, optOrLocale?: Partial<_mmstack_translate.FormatListOptions> | _angular_core.Signal<Partial<_mmstack_translate.FormatListOptions>> | string | _angular_core.Signal<string>) => string;
|
|
528
|
+
relativeTime: (value: (number | null | undefined) | _angular_core.Signal<number | null | undefined>, unit: _mmstack_translate.RelativeTimeUnit | _angular_core.Signal<_mmstack_translate.RelativeTimeUnit>, optOrLocale?: Partial<_mmstack_translate.FormatRelativeTimeOptions> | _angular_core.Signal<Partial<_mmstack_translate.FormatRelativeTimeOptions>> | string | _angular_core.Signal<string>) => string;
|
|
529
|
+
number: (value: (number | null | undefined) | _angular_core.Signal<number | null | undefined>, optOrLocale?: Partial<_mmstack_translate.FormatNumberOptions> | _angular_core.Signal<Partial<_mmstack_translate.FormatNumberOptions>> | string | _angular_core.Signal<string>) => string;
|
|
530
|
+
percent: (value: (number | null | undefined) | _angular_core.Signal<number | null | undefined>, optOrLocale?: Partial<_mmstack_translate.FormatPercentOptions> | _angular_core.Signal<Partial<_mmstack_translate.FormatPercentOptions>> | string | _angular_core.Signal<string>) => string;
|
|
531
|
+
currency: (value: (number | null | undefined) | _angular_core.Signal<number | null | undefined>, currency: string | _angular_core.Signal<string>, optOrLocale?: Partial<_mmstack_translate.FormatCurrencyOptions> | _angular_core.Signal<Partial<_mmstack_translate.FormatCurrencyOptions>> | string | _angular_core.Signal<string>) => string;
|
|
532
|
+
};
|
|
303
533
|
|
|
304
534
|
type BaseConfig = Omit<IntlConfig, 'locale' | 'messages'> & {
|
|
305
535
|
/** Checks next locale is in provided array before switching locales */
|
|
@@ -325,6 +555,7 @@ type DynamicConfig = BaseConfig & {
|
|
|
325
555
|
};
|
|
326
556
|
type Config = RouteBasedConfig | DynamicConfig;
|
|
327
557
|
declare function provideIntlConfig(config: Config): Provider[];
|
|
558
|
+
declare function injectDefaultLocale(): string;
|
|
328
559
|
declare function injectSupportedLocales(): string[];
|
|
329
560
|
declare function injectIntl(): Signal<_formatjs_intl.IntlShape<string>>;
|
|
330
561
|
/**
|
|
@@ -373,7 +604,18 @@ type SignalTFunction<TMap extends AnyStringRecord> = <TKey extends keyof TMap &
|
|
|
373
604
|
type TFunctionWithSignalConstructor<TMap extends AnyStringRecord, TFN extends TFunction<TMap>> = TFN & {
|
|
374
605
|
asSignal: SignalTFunction<TMap>;
|
|
375
606
|
};
|
|
376
|
-
|
|
607
|
+
/**
|
|
608
|
+
* Shape accepted by a namespace loader: a direct `CompiledTranslation`, or an
|
|
609
|
+
* ES-module-style object exposing one as `default` or `translation`. Lets
|
|
610
|
+
* callers write `() => import('./quote.namespace')` instead of the more
|
|
611
|
+
* verbose `() => import('./quote.namespace').then((m) => m.default)`.
|
|
612
|
+
*/
|
|
613
|
+
type LoadedTranslation<T extends CompiledTranslation<UnknownStringKeyObject, string>> = T | {
|
|
614
|
+
default: T;
|
|
615
|
+
} | {
|
|
616
|
+
translation: T;
|
|
617
|
+
};
|
|
618
|
+
declare function registerNamespace<TDefault extends CompiledTranslation<UnknownStringKeyObject, string>>(defaultTranslation: () => Promise<LoadedTranslation<TDefault>>, other: Record<string, () => Promise<LoadedTranslation<CompiledTranslation<UnknownStringKeyObject, inferCompiledTranslationNamespace<TDefault>, string>>>>): {
|
|
377
619
|
injectNamespaceT: () => TFunctionWithSignalConstructor<inferCompiledTranslationMap<TDefault>, TFunction<inferCompiledTranslationMap<TDefault>>>;
|
|
378
620
|
resolveNamespaceTranslation: ResolveFn<void>;
|
|
379
621
|
};
|
|
@@ -407,6 +649,9 @@ declare function injectUnsafeT(): {
|
|
|
407
649
|
asSignal(key: string, params?: () => Record<string, string | number>): Signal<string>;
|
|
408
650
|
};
|
|
409
651
|
|
|
652
|
+
/**
|
|
653
|
+
* @internal
|
|
654
|
+
*/
|
|
410
655
|
declare function injectResolveParamLocale(snapshot: ActivatedRouteSnapshot): string;
|
|
411
656
|
|
|
412
657
|
/**
|
|
@@ -484,10 +729,10 @@ declare function provideMockTranslations(options?: MockTranslationOptions): Prov
|
|
|
484
729
|
|
|
485
730
|
declare abstract class Translate<TInput extends string, T extends CompiledTranslation<UnknownStringKeyObject, string>, TMap extends inferCompiledTranslationMap<T> = inferCompiledTranslationMap<T>, TKey extends TInput & keyof TMap & string = TInput & keyof TMap & string> {
|
|
486
731
|
private readonly t;
|
|
487
|
-
readonly translate:
|
|
732
|
+
readonly translate: _angular_core.InputSignal<TMap[TKey] extends void ? TKey | [key: TKey] : [key: TKey, vars: TMap[TKey]]>;
|
|
488
733
|
constructor();
|
|
489
|
-
static ɵfac:
|
|
490
|
-
static ɵdir:
|
|
734
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<Translate<any, any, any, any>, never>;
|
|
735
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<Translate<any, any, any, any>, never, never, { "translate": { "alias": "translate"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
491
736
|
}
|
|
492
737
|
|
|
493
738
|
type TransformTFn<T extends CompiledTranslation<UnknownStringKeyObject, string>, TMap extends inferCompiledTranslationMap<T>> = <TKey extends keyof TMap & string>(key: TKey, ...args: TMap[TKey] extends void ? [locale?: string] : [TMap[TKey], locale?: string]) => string;
|
|
@@ -521,5 +766,5 @@ declare abstract class Translator<T extends CompiledTranslation<UnknownStringKey
|
|
|
521
766
|
*/
|
|
522
767
|
declare function withParams<const P extends Record<string, unknown>, const S extends string = string>(message: S): WithParams<P, S>;
|
|
523
768
|
|
|
524
|
-
export { Translate, Translator, canMatchLocale, compileTranslation, createNamespace, formatCurrency, formatDate, formatDisplayName, formatList, formatNumber, formatPercent, formatRelativeTime, injectAddTranslations, injectDynamicLocale, injectIntl, injectResolveParamLocale, injectSupportedLocales, injectUnsafeT, provideIntlConfig, provideMockTranslations, registerNamespace, registerRemoteNamespace, withParams };
|
|
525
|
-
export type { CompiledTranslation, FormatCurrencyOptions, FormatDateOptions, FormatDisplayNameOptions, FormatListOptions, FormatNumberOptions, FormatPercentOptions, FormatRelativeTimeOptions, RelativeTimeUnit, SupportedDateInput, SupportedListInput, inferCompiledTranslationMap, inferCompiledTranslationNamespace, inferCompiledTranslationShape, mergeTranslationMaps };
|
|
769
|
+
export { Translate, Translator, canMatchLocale, compileTranslation, createNamespace, formatCurrency, formatDate, formatDisplayName, formatList, formatNumber, formatPercent, formatRelativeTime, injectAddTranslations, injectDefaultLocale, injectDynamicLocale, injectFormatCurrency, injectFormatDate, injectFormatDisplayName, injectFormatList, injectFormatNumber, injectFormatPercent, injectFormatRelativeTime, injectFormatters, injectIntl, injectResolveParamLocale, injectSupportedLocales, injectUnsafeT, provideFormatCurrencyDefaults, provideFormatDateDefaults, provideFormatDefaults, provideFormatDisplayNameDefaults, provideFormatListDefaults, provideFormatNumberDefaults, provideFormatPercentDefaults, provideFormatRelativeTimeDefaults, provideIntlConfig, provideMockTranslations, registerNamespace, registerRemoteNamespace, withParams };
|
|
770
|
+
export type { CompiledTranslation, FormatCurrencyOptions, FormatDateOptions, FormatDisplayNameOptions, FormatListOptions, FormatNumberOptions, FormatPercentOptions, FormatRelativeTimeOptions, RelativeTimeUnit, SupportedDateInput, SupportedListInput, UnsafeFormatCurrencyOptions, UnsafeFormatDateOptions, UnsafeFormatDisplayNameOptions, UnsafeFormatListOptions, UnsafeFormatNumberOptions, UnsafeFormatPercentOptions, UnsafeFormatRelativeTimeOptions, inferCompiledTranslationMap, inferCompiledTranslationNamespace, inferCompiledTranslationShape, mergeTranslationMaps };
|