@mmstack/translate 19.3.5 → 19.3.7

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.
@@ -1,5 +1,46 @@
1
1
  import { type Signal } from '@angular/core';
2
- declare const FORMAT_PRESETS: Record<string, Intl.DateTimeFormatOptions>;
2
+ declare const FORMAT_PRESETS: {
3
+ short: {
4
+ dateStyle: "short";
5
+ timeStyle: "short";
6
+ };
7
+ medium: {
8
+ dateStyle: "medium";
9
+ timeStyle: "medium";
10
+ };
11
+ long: {
12
+ dateStyle: "long";
13
+ timeStyle: "long";
14
+ };
15
+ full: {
16
+ dateStyle: "full";
17
+ timeStyle: "full";
18
+ };
19
+ shortDate: {
20
+ dateStyle: "short";
21
+ };
22
+ mediumDate: {
23
+ dateStyle: "medium";
24
+ };
25
+ longDate: {
26
+ dateStyle: "long";
27
+ };
28
+ fullDate: {
29
+ dateStyle: "full";
30
+ };
31
+ shortTime: {
32
+ timeStyle: "short";
33
+ };
34
+ mediumTime: {
35
+ timeStyle: "medium";
36
+ };
37
+ longTime: {
38
+ timeStyle: "long";
39
+ };
40
+ fullTime: {
41
+ timeStyle: "full";
42
+ };
43
+ };
3
44
  type DateFormat = keyof typeof FORMAT_PRESETS;
4
45
  /**
5
46
  * Supported date inputs
@@ -17,19 +58,44 @@ export type FormatDateOptions = {
17
58
  * Format to use for formatting
18
59
  * @default 'medium'
19
60
  */
20
- format?: DateFormat;
61
+ format?: DateFormat | Intl.DateTimeFormatOptions;
21
62
  /**
22
- * Locale to use for formatting, opts out to dynamic locale changes
63
+ * Locale to use for formatting
23
64
  */
65
+ locale: string;
66
+ };
67
+ /**
68
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
69
+ */
70
+ export type UnsafeFormatDateOptions = Omit<FormatDateOptions, 'locale'> & {
71
+ /** Optional locale string falling back to the legacy global signal */
24
72
  locale?: string;
25
73
  };
26
74
  /**
27
- * Format a date using the current or provided locale & timezone
28
- * By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
29
- *
30
- * @param date - Date to format
31
- * @param opt - Options for formatting
32
- * @returns Formatted date string
75
+ * @example formatDate(this.date, this.locale)
76
+ */
77
+ export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, locale: string | Signal<string>): string;
78
+ /**
79
+ * @example formatDate(this.date, { locale: 'sl-SI', format: 'shortDate' })
80
+ */
81
+ export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt: FormatDateOptions | Signal<FormatDateOptions>): string;
82
+ /**
83
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
84
+ * Use `injectFormatDate()` instead, or pass locale explicitly.
85
+ * @example formatDate(this.date)
86
+ */
87
+ export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt?: UnsafeFormatDateOptions | Signal<UnsafeFormatDateOptions>): string;
88
+ declare const provideFormatDateDefaults: (valueOrFn: Omit<Partial<FormatDateOptions>, "locale"> | (() => Omit<Partial<FormatDateOptions>, "locale"> | Signal<Omit<Partial<FormatDateOptions>, "locale">>)) => import("@angular/core").Provider;
89
+ /**
90
+ * Provide application-wide defaults for date formatting presets and timezones.
91
+ * @example provideFormatDateDefaults({ format: 'shortDate'})
92
+ */
93
+ export { provideFormatDateDefaults };
94
+ /**
95
+ * Inject a context-safe date formatting function tied to the current injector.
96
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
97
+ * @example
98
+ * const formatDate = injectFormatDate();
99
+ * readonly displayDate = computed(() => formatDate(this.date()));
33
100
  */
34
- export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt?: FormatDateOptions | Signal<FormatDateOptions>): string;
35
- export {};
101
+ export declare function injectFormatDate(): (date: SupportedDateInput | Signal<SupportedDateInput>, optOrLocale?: Partial<FormatDateOptions> | Signal<Partial<FormatDateOptions>> | string | Signal<string>) => string;
@@ -1,26 +1,51 @@
1
- import { Signal } from '@angular/core';
1
+ import { type Signal } from '@angular/core';
2
2
  /**
3
3
  * Options for formatting a display name
4
4
  */
5
5
  export type FormatDisplayNameOptions = {
6
6
  /**
7
7
  * The display style for the result set
8
+ * @default 'long'
8
9
  */
9
- style: Intl.RelativeTimeFormatStyle;
10
+ style?: Intl.RelativeTimeFormatStyle;
10
11
  /**
11
- * Locale to use for formatting, opts out to dynamic locale changes
12
+ * Locale to use for formatting
12
13
  */
14
+ locale: string;
15
+ };
16
+ /**
17
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
18
+ */
19
+ export type UnsafeFormatDisplayNameOptions = Omit<FormatDisplayNameOptions, 'locale'> & {
20
+ /** Optional locale string falling back to the legacy global signal */
13
21
  locale?: string;
14
22
  };
15
23
  type SupportedCode = string | null | undefined;
16
24
  /**
17
- * Format a display name using the current or provided locale
18
- * By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
19
- *
20
- * @param value - The code to format
21
- * @param type - The type of display name to format
22
- * @param opt - Options for formatting
23
- * @returns Formatted display name string
25
+ * @example formatDisplayName(this.value, 'region', this.locale)
26
+ */
27
+ export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, locale: string | Signal<string>): string;
28
+ /**
29
+ * @example formatDisplayName(this.value, 'region', {locale: 'en-US', style: 'long'})
30
+ */
31
+ export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions>): string;
32
+ /**
33
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
34
+ * Use `injectFormatDisplayName()` instead, or pass locale explicitly.
35
+ * @example formatDisplayName(this.value)
36
+ */
37
+ export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt?: UnsafeFormatDisplayNameOptions | Signal<UnsafeFormatDisplayNameOptions>): string;
38
+ declare const provideFormatDisplayNameDefaults: (valueOrFn: Omit<Partial<FormatDisplayNameOptions>, "locale"> | (() => Omit<Partial<FormatDisplayNameOptions>, "locale"> | Signal<Omit<Partial<FormatDisplayNameOptions>, "locale">>)) => import("@angular/core").Provider;
39
+ /**
40
+ * Provide application-wide defaults for display name formatting presets and timezones.
41
+ * @example provideFormatDisplayNameDefaults({ style: 'long'})
42
+ */
43
+ export { provideFormatDisplayNameDefaults };
44
+ /**
45
+ * Inject a context-safe date formatting function tied to the current injector.
46
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
47
+ * @example
48
+ * const formatDisplayName = injectFormatDisplayName();
49
+ * readonly region = computed(() => formatDisplayName('US', 'region'));
24
50
  */
25
- export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt?: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions>): string;
26
- export {};
51
+ export declare function injectFormatDisplayName(): (value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, localeOrOpt?: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions> | string | Signal<string>) => string;
@@ -1,5 +1,6 @@
1
1
  export * from './date';
2
2
  export * from './display-name';
3
+ export * from './injection';
3
4
  export * from './list';
4
5
  export * from './numeric';
5
6
  export * from './relative-time';
@@ -0,0 +1,27 @@
1
+ import type { Provider } from '@angular/core';
2
+ import { provideFormatDateDefaults } from './date';
3
+ import { provideFormatDisplayNameDefaults } from './display-name';
4
+ import { provideFormatListDefaults } from './list';
5
+ import { provideFormatCurrencyDefaults, provideFormatNumberDefaults, provideFormatPercentDefaults } from './numeric';
6
+ import type { inferProvideParameter } from './provide-defaults';
7
+ import { provideFormatRelativeTimeDefaults } from './relative-time';
8
+ type FormatDefaults = {
9
+ date?: inferProvideParameter<typeof provideFormatDateDefaults>;
10
+ displayName?: inferProvideParameter<typeof provideFormatDisplayNameDefaults>;
11
+ list?: inferProvideParameter<typeof provideFormatListDefaults>;
12
+ relativeTime?: inferProvideParameter<typeof provideFormatRelativeTimeDefaults>;
13
+ number?: inferProvideParameter<typeof provideFormatNumberDefaults>;
14
+ percent?: inferProvideParameter<typeof provideFormatPercentDefaults>;
15
+ currency?: inferProvideParameter<typeof provideFormatCurrencyDefaults>;
16
+ };
17
+ export declare function provideFormatDefaults(cfg: FormatDefaults): Provider[];
18
+ export declare function injectFormatters(): {
19
+ date: (date: import("@mmstack/translate").SupportedDateInput | import("@angular/core").Signal<import("@mmstack/translate").SupportedDateInput>, optOrLocale?: Partial<import("@mmstack/translate").FormatDateOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatDateOptions>> | string | import("@angular/core").Signal<string>) => string;
20
+ displayName: (value: (string | null | undefined) | import("@angular/core").Signal<string | null | undefined>, type: Intl.DisplayNamesType | import("@angular/core").Signal<Intl.DisplayNamesType>, localeOrOpt?: import("@mmstack/translate").FormatDisplayNameOptions | import("@angular/core").Signal<import("@mmstack/translate").FormatDisplayNameOptions> | string | import("@angular/core").Signal<string>) => string;
21
+ list: (value: import("@mmstack/translate").SupportedListInput | import("@angular/core").Signal<import("@mmstack/translate").SupportedListInput>, optOrLocale?: Partial<import("@mmstack/translate").FormatListOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatListOptions>> | string | import("@angular/core").Signal<string>) => string;
22
+ relativeTime: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, unit: import("@mmstack/translate").RelativeTimeUnit | import("@angular/core").Signal<import("@mmstack/translate").RelativeTimeUnit>, optOrLocale?: Partial<import("@mmstack/translate").FormatRelativeTimeOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatRelativeTimeOptions>> | string | import("@angular/core").Signal<string>) => string;
23
+ number: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, optOrLocale?: Partial<import("@mmstack/translate").FormatNumberOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatNumberOptions>> | string | import("@angular/core").Signal<string>) => string;
24
+ percent: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, optOrLocale?: Partial<import("@mmstack/translate").FormatPercentOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatPercentOptions>> | string | import("@angular/core").Signal<string>) => string;
25
+ currency: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, currency: string | import("@angular/core").Signal<string>, optOrLocale?: Partial<import("@mmstack/translate").FormatCurrencyOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatCurrencyOptions>> | string | import("@angular/core").Signal<string>) => string;
26
+ };
27
+ export {};
@@ -8,24 +8,51 @@ export type SupportedListInput = string[] | null | undefined;
8
8
  export type FormatListOptions = {
9
9
  /**
10
10
  * The type of list to format
11
+ * @default 'conjunction'
11
12
  */
12
13
  type?: ListType;
13
14
  /**
14
15
  * The style of list to format
16
+ * @default 'long'
15
17
  */
16
18
  style?: ListStyle;
17
19
  /**
18
- * Locale to use for formatting, opts out to dynamic locale changes
20
+ * Locale to use for formatting
19
21
  */
22
+ locale: string;
23
+ };
24
+ /**
25
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
26
+ */
27
+ export type UnsafeFormatListOptions = Omit<FormatListOptions, 'locale'> & {
28
+ /** Optional locale string falling back to the legacy global signal */
20
29
  locale?: string;
21
30
  };
22
31
  /**
23
- * Format a list using the current or provided locale
24
- * By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
25
- *
26
- * @param value - The list to format
27
- * @param opt - Options for formatting
28
- * @returns Formatted list string
32
+ * @example formatList(this.items, this.locale)
33
+ */
34
+ export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, locale: string | Signal<string>): string;
35
+ /**
36
+ * @example formatList(this.items, { locale: 'sl-SI', type: 'disjunction' })
37
+ */
38
+ export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt: FormatListOptions | Signal<FormatListOptions>): string;
39
+ /**
40
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
41
+ * Use `injectFormatList()` instead, or pass locale explicitly.
42
+ * @example formatList(this.items)
43
+ */
44
+ export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt?: UnsafeFormatListOptions | Signal<UnsafeFormatListOptions>): string;
45
+ declare const provideFormatListDefaults: (valueOrFn: Omit<Partial<FormatListOptions>, "locale"> | (() => Omit<Partial<FormatListOptions>, "locale"> | Signal<Omit<Partial<FormatListOptions>, "locale">>)) => import("@angular/core").Provider;
46
+ /**
47
+ * Provide application-wide defaults for list formatting presets.
48
+ * @example provideFormatListDefaults({ type: 'disjunction' })
49
+ */
50
+ export { provideFormatListDefaults };
51
+ /**
52
+ * Inject a context-safe list formatting function tied to the current injector.
53
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
54
+ * @example
55
+ * const formatList = injectFormatList();
56
+ * readonly displayList = computed(() => formatList(this.items()));
29
57
  */
30
- export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt?: FormatListOptions | Signal<FormatListOptions>): string;
31
- export {};
58
+ export declare function injectFormatList(): (value: SupportedListInput | Signal<SupportedListInput>, optOrLocale?: Partial<FormatListOptions> | Signal<Partial<FormatListOptions>> | string | Signal<string>) => string;
@@ -7,6 +7,7 @@ type SupportedNumberValue = number | null | undefined;
7
7
  export type FormatNumberOptions = {
8
8
  /**
9
9
  * The notation to use for formatting
10
+ * @default 'standard'
10
11
  */
11
12
  notation?: NumberNotation;
12
13
  /**
@@ -19,27 +20,54 @@ export type FormatNumberOptions = {
19
20
  maxFractionDigits?: number;
20
21
  /**
21
22
  * Whether to use grouping
23
+ * @default true
22
24
  */
23
25
  useGrouping?: boolean;
24
- /**
25
- * Locale to use for formatting, opts out to dynamic locale changes
26
- */
27
- locale?: string;
28
26
  /**
29
27
  * If the number is not a valid number, return formatted 0. By default formatter returns an empty string
30
28
  * @default false
31
29
  */
32
30
  fallbackToZero?: boolean;
31
+ /**
32
+ * Locale to use for formatting
33
+ */
34
+ locale: string;
35
+ };
36
+ /**
37
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
38
+ */
39
+ export type UnsafeFormatNumberOptions = Omit<FormatNumberOptions, 'locale'> & {
40
+ /** Optional locale string falling back to the legacy global signal */
41
+ locale?: string;
33
42
  };
34
43
  /**
35
- * Format a number using the current or provided locale
36
- * By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
37
- *
38
- * @param number - Number to format
39
- * @param opt - Options for formatting
40
- * @returns Formatted number string
44
+ * @example formatNumber(this.value, this.locale)
45
+ */
46
+ export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, locale: string | Signal<string>): string;
47
+ /**
48
+ * @example formatNumber(this.value, { locale: 'de-DE', notation: 'compact' })
41
49
  */
42
- export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: FormatNumberOptions | Signal<FormatNumberOptions>): string;
50
+ export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt: FormatNumberOptions | Signal<FormatNumberOptions>): string;
51
+ /**
52
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
53
+ * Use `injectFormatNumber()` instead, or pass locale explicitly.
54
+ * @example formatNumber(this.value)
55
+ */
56
+ export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: UnsafeFormatNumberOptions | Signal<UnsafeFormatNumberOptions>): string;
57
+ declare const provideFormatNumberDefaults: (valueOrFn: Omit<Partial<FormatNumberOptions>, "locale"> | (() => Omit<Partial<FormatNumberOptions>, "locale"> | Signal<Omit<Partial<FormatNumberOptions>, "locale">>)) => import("@angular/core").Provider;
58
+ /**
59
+ * Provide application-wide defaults for number formatting presets.
60
+ * @example provideFormatNumberDefaults({ notation: 'compact' })
61
+ */
62
+ export { provideFormatNumberDefaults };
63
+ /**
64
+ * Inject a context-safe number formatting function tied to the current injector.
65
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
66
+ * @example
67
+ * const formatNumber = injectFormatNumber();
68
+ * readonly display = computed(() => formatNumber(this.value()));
69
+ */
70
+ export declare function injectFormatNumber(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, optOrLocale?: Partial<FormatNumberOptions> | Signal<Partial<FormatNumberOptions>> | string | Signal<string>) => string;
43
71
  /**
44
72
  * Options for formatting a percentage value
45
73
  */
@@ -52,40 +80,97 @@ export type FormatPercentOptions = {
52
80
  * Maximum number of fraction digits to use
53
81
  */
54
82
  maxFractionDigits?: number;
55
- /**
56
- * Locale to use for formatting, opts out to dynamic locale changes
57
- */
58
- locale?: string;
59
83
  /**
60
84
  * If the number is not a valid number, return formatted 0. By default formatter returns an empty string
61
85
  * @default false
62
86
  */
63
87
  fallbackToZero?: boolean;
88
+ /**
89
+ * Locale to use for formatting
90
+ */
91
+ locale: string;
92
+ };
93
+ /**
94
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
95
+ */
96
+ export type UnsafeFormatPercentOptions = Omit<FormatPercentOptions, 'locale'> & {
97
+ /** Optional locale string falling back to the legacy global signal */
98
+ locale?: string;
64
99
  };
65
100
  /**
66
- * Format a percentage using the current or provided locale
67
- * By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
68
- *
69
- * @param number - Number to format
70
- * @param opt - Options for formatting
71
- * @returns Formatted percentage string
101
+ * @example formatPercent(this.value, this.locale)
72
102
  */
73
- export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: FormatPercentOptions | Signal<FormatPercentOptions>): string;
103
+ export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, locale: string | Signal<string>): string;
104
+ /**
105
+ * @example formatPercent(this.value, { locale: 'de-DE', maxFractionDigits: 2 })
106
+ */
107
+ export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt: FormatPercentOptions | Signal<FormatPercentOptions>): string;
108
+ /**
109
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
110
+ * Use `injectFormatPercent()` instead, or pass locale explicitly.
111
+ * @example formatPercent(this.value)
112
+ */
113
+ export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: UnsafeFormatPercentOptions | Signal<UnsafeFormatPercentOptions>): string;
114
+ declare const provideFormatPercentDefaults: (valueOrFn: Omit<Partial<FormatPercentOptions>, "locale"> | (() => Omit<Partial<FormatPercentOptions>, "locale"> | Signal<Omit<Partial<FormatPercentOptions>, "locale">>)) => import("@angular/core").Provider;
115
+ /**
116
+ * Provide application-wide defaults for percent formatting presets.
117
+ * @example provideFormatPercentDefaults({ maxFractionDigits: 1 })
118
+ */
119
+ export { provideFormatPercentDefaults };
120
+ /**
121
+ * Inject a context-safe percent formatting function tied to the current injector.
122
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
123
+ */
124
+ export declare function injectFormatPercent(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, optOrLocale?: Partial<FormatPercentOptions> | Signal<Partial<FormatPercentOptions>> | string | Signal<string>) => string;
74
125
  type CurrencyDisplay = 'symbol' | 'narrowSymbol' | 'code' | 'name';
75
126
  /**
76
127
  * Options for formatting a currency
77
128
  */
78
129
  export type FormatCurrencyOptions = {
79
- display?: CurrencyDisplay;
80
130
  /**
81
- * Locale to use for formatting, opts out to dynamic locale changes
131
+ * The display type for the currency format
132
+ * @default 'symbol'
82
133
  */
83
- locale?: string;
134
+ display?: CurrencyDisplay;
84
135
  /**
85
136
  * If the number is not a valid number, return formatted 0. By default formatter returns an empty string
86
137
  * @default false
87
138
  */
88
139
  fallbackToZero?: boolean;
140
+ /**
141
+ * Locale to use for formatting
142
+ */
143
+ locale: string;
144
+ };
145
+ /**
146
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
147
+ */
148
+ export type UnsafeFormatCurrencyOptions = Omit<FormatCurrencyOptions, 'locale'> & {
149
+ /** Optional locale string falling back to the legacy global signal */
150
+ locale?: string;
89
151
  };
90
- export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt?: FormatCurrencyOptions | Signal<FormatCurrencyOptions>): string;
91
- export {};
152
+ /**
153
+ * @example formatCurrency(this.value, 'USD', this.locale)
154
+ */
155
+ export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, locale: string | Signal<string>): string;
156
+ /**
157
+ * @example formatCurrency(this.value, 'EUR', { locale: 'de-DE', display: 'code' })
158
+ */
159
+ export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt: FormatCurrencyOptions | Signal<FormatCurrencyOptions>): string;
160
+ /**
161
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
162
+ * Use `injectFormatCurrency()` instead, or pass locale explicitly.
163
+ * @example formatCurrency(this.value, 'USD')
164
+ */
165
+ export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt?: UnsafeFormatCurrencyOptions | Signal<UnsafeFormatCurrencyOptions>): string;
166
+ declare const provideFormatCurrencyDefaults: (valueOrFn: Omit<Partial<FormatCurrencyOptions>, "locale"> | (() => Omit<Partial<FormatCurrencyOptions>, "locale"> | Signal<Omit<Partial<FormatCurrencyOptions>, "locale">>)) => import("@angular/core").Provider;
167
+ /**
168
+ * Provide application-wide defaults for currency formatting presets.
169
+ * @example provideFormatCurrencyDefaults({ display: 'code' })
170
+ */
171
+ export { provideFormatCurrencyDefaults };
172
+ /**
173
+ * Inject a context-safe currency formatting function tied to the current injector.
174
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
175
+ */
176
+ export declare function injectFormatCurrency(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, optOrLocale?: Partial<FormatCurrencyOptions> | Signal<Partial<FormatCurrencyOptions>> | string | Signal<string>) => string;
@@ -0,0 +1,5 @@
1
+ import { type Provider, type Signal } from '@angular/core';
2
+ export declare function createFormatterProvider<T extends {
3
+ locale: string;
4
+ }>(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>];
5
+ export type inferProvideParameter<T extends ReturnType<typeof createFormatterProvider>[0]> = Parameters<T>[0];
@@ -14,20 +14,44 @@ export type FormatRelativeTimeOptions = {
14
14
  */
15
15
  numeric?: Intl.RelativeTimeFormatNumeric;
16
16
  /**
17
- * Locale to use for formatting, opts out to dynamic locale changes
17
+ * Locale to use for formatting
18
18
  */
19
+ locale: string;
20
+ };
21
+ /**
22
+ * @deprecated UNSAFE FOR SSR/EDGE. Omiting the locale property forces a fallback to a process-level global singleton.
23
+ */
24
+ export type UnsafeFormatRelativeTimeOptions = Omit<FormatRelativeTimeOptions, 'locale'> & {
25
+ /** Optional locale string falling back to the legacy global signal */
19
26
  locale?: string;
20
27
  };
21
28
  export type RelativeTimeUnit = Intl.RelativeTimeFormatUnit;
22
29
  type SupportedRelativeTimeInput = number | null | undefined;
23
30
  /**
24
- * Format a relative time using the current or provided locale
25
- * By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
26
- *
27
- * @param value - The numeric value to use in the relative time internationalization message
28
- * @param unit - The unit to use in the relative time internationalization message
29
- * @param opt - Options for formatting
30
- * @returns Formatted relative time string
31
+ * @example formatRelativeTime(this.value, this.unit, this.locale)
32
+ */
33
+ export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, locale: string | Signal<string>): string;
34
+ /**
35
+ * @example formatRelativeTime(this.value, 'day', { locale: 'sl-SI', numeric: 'auto' })
36
+ */
37
+ export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt: FormatRelativeTimeOptions | Signal<FormatRelativeTimeOptions>): string;
38
+ /**
39
+ * @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
40
+ * Use `injectFormatRelativeTime()` instead, or pass locale explicitly.
41
+ * @example formatRelativeTime(this.value, 'day')
42
+ */
43
+ export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt?: UnsafeFormatRelativeTimeOptions | Signal<UnsafeFormatRelativeTimeOptions>): string;
44
+ declare const provideFormatRelativeTimeDefaults: (valueOrFn: Omit<Partial<FormatRelativeTimeOptions>, "locale"> | (() => Omit<Partial<FormatRelativeTimeOptions>, "locale"> | Signal<Omit<Partial<FormatRelativeTimeOptions>, "locale">>)) => import("@angular/core").Provider;
45
+ /**
46
+ * Provide application-wide defaults for relative time formatting presets.
47
+ * @example provideFormatRelativeTimeDefaults({ numeric: 'auto' })
48
+ */
49
+ export { provideFormatRelativeTimeDefaults };
50
+ /**
51
+ * Inject a context-safe relative time formatting function tied to the current injector.
52
+ * Uses the libraries locale signal & provided default configuration to react to locale/config changes
53
+ * @example
54
+ * const formatRelativeTime = injectFormatRelativeTime();
55
+ * readonly relativeAge = computed(() => formatRelativeTime(this.delta(), 'day'));
31
56
  */
32
- export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt?: FormatRelativeTimeOptions | Signal<FormatRelativeTimeOptions>): string;
33
- export {};
57
+ export declare function injectFormatRelativeTime(): (value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, optOrLocale?: Partial<FormatRelativeTimeOptions> | Signal<Partial<FormatRelativeTimeOptions>> | string | Signal<string>) => string;
@@ -15,7 +15,28 @@ export type extractParams<T extends string> = T extends `${infer _Start}{${infer
15
15
  type mergeParams<TExtracted extends [string, any]> = {
16
16
  [K in TExtracted as K[0]]: K[1];
17
17
  };
18
- type flattenParams<TKey extends string, TVal> = TVal extends UnknownStringKeyObject ? inferParamTupples<TVal, `${TKey}.`> : TVal extends string ? extractParams<TVal> extends never ? [TKey] : [TKey, mergeParams<extractParams<TVal>>] : never;
18
+ declare const PARAM_BRAND: unique symbol;
19
+ /**
20
+ * Branded string type produced by `withParams<P>(message)`. The brand carries
21
+ * both the declared parameter shape `P` and the original literal message `S` —
22
+ * the literal lives inside the brand (not just on the intersection) so the
23
+ * inference machinery can recover it without going through template-literal
24
+ * pattern matching on a branded intersection (which widens `infer` slots to
25
+ * `string` and breaks auto-extraction). Module-local `unique symbol`, so the
26
+ * brand is not constructible outside this package.
27
+ */
28
+ export type WithParams<P extends Record<string, unknown>, S extends string = string> = S & {
29
+ readonly [PARAM_BRAND]: {
30
+ params: P;
31
+ literal: S;
32
+ };
33
+ };
34
+ type flattenParams<TKey extends string, TVal> = TVal extends {
35
+ readonly [PARAM_BRAND]: {
36
+ params: infer P;
37
+ literal: infer S extends string;
38
+ };
39
+ } ? P extends Record<string, unknown> ? extractParams<S> extends never ? [TKey, P] : [TKey, Omit<mergeParams<extractParams<S>>, keyof P> & P] : [TKey] : TVal extends UnknownStringKeyObject ? inferParamTupples<TVal, `${TKey}.`> : TVal extends string ? extractParams<TVal> extends never ? [TKey] : [TKey, mergeParams<extractParams<TVal>>] : never;
19
40
  type inferParamTupples<T extends UnknownStringKeyObject, TPrefix extends string = ''> = Simplify<{
20
41
  [K in keyof T]: K extends string ? flattenParams<`${TPrefix}${K}`, T[K]> : never;
21
42
  }[keyof T]>;
@@ -27,6 +48,8 @@ type TypeEnsuringAllPlaceholders<PlaceholdersUnion extends string> = StringConta
27
48
  export type extractParamString<T extends string> = T extends `${infer _Start}{${infer Var}}${infer End}` ? Var extends `${infer VarName},${string}` ? `{${VarName}, ${string}}` | extractParamString<End> : `{${Var}}` | extractParamString<End> : never;
28
49
  type inferParamsFromValue<V extends string> = extractParamString<V> extends never ? string : TypeEnsuringAllPlaceholders<extractParamString<V>>;
29
50
  export type inferTranslationShape<T extends UnknownStringKeyObject> = {
30
- [K in keyof T]: T[K] extends UnknownStringKeyObject ? inferTranslationShape<T[K]> : T[K] extends string ? inferParamsFromValue<T[K]> : never;
51
+ [K in keyof T]: T[K] extends {
52
+ readonly [PARAM_BRAND]: any;
53
+ } ? string : T[K] extends UnknownStringKeyObject ? inferTranslationShape<T[K]> : T[K] extends string ? inferParamsFromValue<T[K]> : never;
31
54
  };
32
55
  export {};
@@ -3,6 +3,7 @@ import { ResolveFn } from '@angular/router';
3
3
  import { type CompiledTranslation, type inferCompiledTranslationMap, type inferCompiledTranslationNamespace } from './compile';
4
4
  import { type AnyStringRecord, type UnknownStringKeyObject } from './string-key-object.type';
5
5
  import { TranslationStore } from './translation-store';
6
+ import * as i0 from "@angular/core";
6
7
  type TFunction<TMap extends AnyStringRecord> = <TKey extends keyof TMap & string>(key: TKey, ...args: TMap[TKey] extends void ? [] : [TMap[TKey]]) => string;
7
8
  type SignalTFunction<TMap extends AnyStringRecord> = <TKey extends keyof TMap & string>(key: TKey, ...args: TMap[TKey] extends void ? [] : [() => TMap[TKey]]) => Signal<string>;
8
9
  type TFunctionWithSignalConstructor<TMap extends AnyStringRecord, TFN extends TFunction<TMap>> = TFN & {
@@ -26,4 +27,26 @@ export declare function registerRemoteNamespace<TNS extends string>(ns: TNS, def
26
27
  injectNamespaceT: () => UntypedTFunction<TNS>;
27
28
  resolveNamespaceTranslation: ResolveFn<void>;
28
29
  };
30
+ export declare class UnsafeTKeyMap {
31
+ readonly map: Map<string, string>;
32
+ static ɵfac: i0.ɵɵFactoryDeclaration<UnsafeTKeyMap, never>;
33
+ static ɵprov: i0.ɵɵInjectableDeclaration<UnsafeTKeyMap>;
34
+ }
35
+ /**
36
+ * Power-user escape hatch that returns a fully untyped translation function.
37
+ * Intended for use alongside {@link injectAddTranslations} when translations
38
+ * are added imperatively (e.g. from a remote API), or for cross-namespace
39
+ * lookups where the typed API would be impractical.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const t = injectUnsafeT();
44
+ * t('any.namespace.key', { name: 'Alice', count: 3 });
45
+ * const sig = t.asSignal('any.namespace.key', () => ({ name: name() }));
46
+ * ```
47
+ */
48
+ export declare function injectUnsafeT(): {
49
+ (key: string, params?: Record<string, string | number>): string;
50
+ asSignal(key: string, params?: () => Record<string, string | number>): Signal<string>;
51
+ };
29
52
  export {};
@@ -28,6 +28,11 @@ export declare function provideIntlConfig(config: Config): Provider[];
28
28
  export declare function injectIntlConfig(): Config | undefined;
29
29
  export declare function injectDefaultLocale(): string;
30
30
  export declare function injectSupportedLocales(): string[];
31
+ /**
32
+ * @internal
33
+ * @deprecated will be removed when ng23 drops
34
+ */
35
+ export declare function readLocaleUnsafe(): string;
31
36
  export declare function injectLocaleInternal(): WritableSignal<string>;
32
37
  export declare class TranslationStore {
33
38
  private readonly simpleKeyMap;
@@ -82,4 +87,22 @@ export declare function injectIntl(): Signal<import("@formatjs/intl").IntlShape<
82
87
  export declare function injectDynamicLocale(): WritableSignal<string> & {
83
88
  isLoading: Signal<boolean>;
84
89
  };
90
+ /**
91
+ * Power-user escape hatch for adding translations imperatively (e.g. content
92
+ * loaded from a remote API after bootstrap). Returns a function that registers
93
+ * a flat per-locale map of keys under a given namespace
94
+ *
95
+ * Pair with {@link injectUnsafeT} to read the added keys without compile-time
96
+ * constraints.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const addTranslations = injectAddTranslations();
101
+ * addTranslations('remote', {
102
+ * 'en-US': { greeting: 'Hi {name}' },
103
+ * 'sl-SI': { greeting: 'Zdravo {name}' },
104
+ * });
105
+ * ```
106
+ */
107
+ export declare function injectAddTranslations(): (ns: string, translations: Record<string, Record<string, string>>) => void;
85
108
  export {};