@zucker-framework/i18n 1.0.0
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/LICENSE +201 -0
- package/NOTICE +22 -0
- package/THIRD_PARTY_NOTICES +4 -0
- package/dist/index.d.mts +282 -0
- package/dist/index.d.ts +282 -0
- package/dist/index.js +677 -0
- package/dist/index.mjs +636 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Zucker Framework
|
|
2
|
+
Copyright 2026 Lind and Zucker Framework contributors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0. See LICENSE.
|
|
5
|
+
|
|
6
|
+
The framework includes TypeScript adaptations and enhancements of concepts and
|
|
7
|
+
implementations from hsweb-framework and jetlinks-community, both distributed
|
|
8
|
+
under the Apache License, Version 2.0. Individual packages use different subsets
|
|
9
|
+
of the framework. The TypeScript adaptations and Node.js integrations were
|
|
10
|
+
modified for Zucker Framework; they are not the original upstream distribution.
|
|
11
|
+
|
|
12
|
+
hsweb-framework
|
|
13
|
+
https://github.com/hs-web/hsweb-framework
|
|
14
|
+
Copyright 2020 http://hsweb.me
|
|
15
|
+
|
|
16
|
+
jetlinks-community
|
|
17
|
+
https://github.com/jetlinks/jetlinks-community
|
|
18
|
+
|
|
19
|
+
See THIRD_PARTY_NOTICES for license texts and attribution for bundled dependencies
|
|
20
|
+
and reference implementations relevant to this package. External dependencies
|
|
21
|
+
remain subject to their own licenses. This NOTICE is informational and does not
|
|
22
|
+
modify any license or grant rights to upstream trademarks.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler, Type, DynamicModule, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { BusinessException } from '@zucker-framework/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* MessageSource — i18n message resolution interface.
|
|
7
|
+
*/
|
|
8
|
+
interface MessageSource {
|
|
9
|
+
getMessage(code: string, args?: unknown[], defaultMessage?: string, locale?: string): string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* FileMessageSource — loads messages from JSON files.
|
|
13
|
+
*
|
|
14
|
+
* Expected file structure: {basePath}/{locale}.json
|
|
15
|
+
* JSON format: flat key-value pairs, e.g. { "error.notFound": "Resource not found" }
|
|
16
|
+
*
|
|
17
|
+
* Supports message interpolation with positional args: "Hello {0}, welcome to {1}"
|
|
18
|
+
*/
|
|
19
|
+
declare class FileMessageSource implements MessageSource {
|
|
20
|
+
private readonly basePath;
|
|
21
|
+
private readonly logger;
|
|
22
|
+
private readonly messages;
|
|
23
|
+
private readonly defaultLocale;
|
|
24
|
+
constructor(basePath: string, options?: {
|
|
25
|
+
defaultLocale?: string;
|
|
26
|
+
});
|
|
27
|
+
getMessage(code: string, args?: unknown[], defaultMessage?: string, locale?: string): string;
|
|
28
|
+
private loadLocale;
|
|
29
|
+
private flatten;
|
|
30
|
+
private interpolate;
|
|
31
|
+
clearCache(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* CompositeMessageSource — aggregates multiple message sources.
|
|
35
|
+
* Checks sources in order, returns the first match.
|
|
36
|
+
*/
|
|
37
|
+
declare class CompositeMessageSource implements MessageSource {
|
|
38
|
+
private readonly sources;
|
|
39
|
+
constructor(sources: MessageSource[]);
|
|
40
|
+
getMessage(code: string, args?: unknown[], defaultMessage?: string, locale?: string): string;
|
|
41
|
+
addSource(source: MessageSource): void;
|
|
42
|
+
/**
|
|
43
|
+
* Add multiple sources at once.
|
|
44
|
+
*/
|
|
45
|
+
addSources(sources: MessageSource[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get the number of registered sources.
|
|
48
|
+
*/
|
|
49
|
+
getSourceCount(): number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* LocaleContext -- uses AsyncLocalStorage to bind the current locale
|
|
54
|
+
* to the execution context (request scope).
|
|
55
|
+
*/
|
|
56
|
+
declare class LocaleContext {
|
|
57
|
+
private static defaultLocale;
|
|
58
|
+
static setDefault(locale: string): void;
|
|
59
|
+
static getCurrent(): string;
|
|
60
|
+
static run<T>(locale: string, fn: () => T): T;
|
|
61
|
+
static runAsync<T>(locale: string, fn: () => Promise<T>): Promise<T>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* NestJS interceptor that sets the locale from the Accept-Language header.
|
|
65
|
+
*/
|
|
66
|
+
declare class LocaleInterceptor implements NestInterceptor {
|
|
67
|
+
private readonly supportedLocales;
|
|
68
|
+
private readonly defaultLocale;
|
|
69
|
+
constructor(options?: {
|
|
70
|
+
supportedLocales?: string[];
|
|
71
|
+
defaultLocale?: string;
|
|
72
|
+
});
|
|
73
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
74
|
+
private parseLocale;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* I18nException — an exception whose message is resolved via i18n at response time.
|
|
79
|
+
*
|
|
80
|
+
* Stores a message code and interpolation args. The actual i18n resolution
|
|
81
|
+
* happens when getMessage() is called (typically in an exception filter).
|
|
82
|
+
*/
|
|
83
|
+
declare class I18nException extends BusinessException {
|
|
84
|
+
readonly i18nCode: string;
|
|
85
|
+
readonly i18nArgs: unknown[];
|
|
86
|
+
constructor(code: string, args?: unknown[], fallbackMessage?: string);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* I18nSpec — supports nested i18n parameter resolution.
|
|
91
|
+
*
|
|
92
|
+
* Allows i18n message codes whose arguments themselves need i18n resolution.
|
|
93
|
+
*
|
|
94
|
+
* Reference: jetlinks I18nSpec
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const spec = I18nSpec.of('message.scene.term.full_name', 'Property: {0}/{1}',
|
|
99
|
+
* 'Temperature',
|
|
100
|
+
* I18nSpec.of('message.property.recent', 'Current Value'),
|
|
101
|
+
* );
|
|
102
|
+
* const resolved = spec.resolve(messageSource);
|
|
103
|
+
* // => "Property: Temperature/Current Value" (or localized)
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare class I18nSpec {
|
|
107
|
+
/** i18n message code; if empty, defaultMessage is returned as-is */
|
|
108
|
+
code?: string;
|
|
109
|
+
/** Fallback message when code is not found or not provided */
|
|
110
|
+
defaultMessage?: string;
|
|
111
|
+
/** Nested i18n-aware arguments */
|
|
112
|
+
args: I18nSpec[];
|
|
113
|
+
constructor(code?: string, defaultMessage?: string, args?: I18nSpec[]);
|
|
114
|
+
/**
|
|
115
|
+
* Create an I18nSpec with optional nested args.
|
|
116
|
+
* Args can be strings (treated as plain defaults) or I18nSpec instances.
|
|
117
|
+
*/
|
|
118
|
+
static of(code: string, defaultMessage?: string, ...args: Array<string | I18nSpec>): I18nSpec;
|
|
119
|
+
/**
|
|
120
|
+
* Add a nested i18n argument.
|
|
121
|
+
*/
|
|
122
|
+
withArg(code: string, defaultMessage?: string, ...args: Array<string | I18nSpec>): this;
|
|
123
|
+
/**
|
|
124
|
+
* Add an existing I18nSpec as a nested argument.
|
|
125
|
+
*/
|
|
126
|
+
withArgSpec(spec: I18nSpec): this;
|
|
127
|
+
/**
|
|
128
|
+
* Resolve this spec to a final message using the given MessageSource.
|
|
129
|
+
* Recursively resolves nested args first.
|
|
130
|
+
*/
|
|
131
|
+
resolve(messageSource: MessageSource, locale?: string): string;
|
|
132
|
+
/**
|
|
133
|
+
* Create a shallow copy of this spec.
|
|
134
|
+
*/
|
|
135
|
+
copy(): I18nSpec;
|
|
136
|
+
private resolveMessage;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Format a message template with positional or named parameters.
|
|
141
|
+
*
|
|
142
|
+
* Supports positional arguments `{0}, {1}` and named arguments `{name}, {count}`.
|
|
143
|
+
*
|
|
144
|
+
* @example formatMessage('Hello {0}, you have {1} messages', ['Alice', 5])
|
|
145
|
+
* @example formatMessage('Hello {name}, you have {count} messages', { name: 'Alice', count: 5 })
|
|
146
|
+
*/
|
|
147
|
+
declare function formatMessage(template: string, params: unknown[] | Record<string, unknown>): string;
|
|
148
|
+
/**
|
|
149
|
+
* Simple plural selection (ICU MessageFormat style).
|
|
150
|
+
*
|
|
151
|
+
* Chooses among `zero`, `one` and `other` forms based on `count`.
|
|
152
|
+
* The selected form is then interpolated with `{count}` replaced by the actual
|
|
153
|
+
* number (formatted according to `locale` when provided).
|
|
154
|
+
*
|
|
155
|
+
* @example pluralize(0, { zero: '没有消息', one: '1 条消息', other: '{count} 条消息' })
|
|
156
|
+
* @example pluralize(5, { zero: '没有消息', one: '1 条消息', other: '{count} 条消息' })
|
|
157
|
+
*/
|
|
158
|
+
declare function pluralize(count: number, forms: {
|
|
159
|
+
zero?: string;
|
|
160
|
+
one?: string;
|
|
161
|
+
other: string;
|
|
162
|
+
}, locale?: string): string;
|
|
163
|
+
/**
|
|
164
|
+
* Format a date using `Intl.DateTimeFormat`.
|
|
165
|
+
*
|
|
166
|
+
* @param date Date instance or epoch-milliseconds timestamp
|
|
167
|
+
* @param style Predefined date style — `'short'`, `'medium'` (default),
|
|
168
|
+
* `'long'` or `'full'`
|
|
169
|
+
* @param locale BCP-47 locale tag; defaults to the current context locale
|
|
170
|
+
*/
|
|
171
|
+
declare function formatDate(date: Date | number, style?: 'short' | 'medium' | 'long' | 'full', locale?: string): string;
|
|
172
|
+
/**
|
|
173
|
+
* Format a number using `Intl.NumberFormat`.
|
|
174
|
+
*
|
|
175
|
+
* @param value The numeric value
|
|
176
|
+
* @param style `'decimal'` (default), `'currency'` or `'percent'`
|
|
177
|
+
* @param options Additional options — currently only `currency` (ISO 4217 code,
|
|
178
|
+
* required when `style` is `'currency'`)
|
|
179
|
+
* @param locale BCP-47 locale tag; defaults to the current context locale
|
|
180
|
+
*/
|
|
181
|
+
declare function formatNumber(value: number, style?: 'decimal' | 'currency' | 'percent', options?: {
|
|
182
|
+
currency?: string;
|
|
183
|
+
}, locale?: string): string;
|
|
184
|
+
/**
|
|
185
|
+
* Format a date as a human-friendly relative time string
|
|
186
|
+
* (e.g. "3 hours ago", "in 2 days") using `Intl.RelativeTimeFormat`.
|
|
187
|
+
*
|
|
188
|
+
* @param date Date instance or epoch-milliseconds timestamp
|
|
189
|
+
* @param locale BCP-47 locale tag; defaults to the current context locale
|
|
190
|
+
*/
|
|
191
|
+
declare function formatRelativeTime(date: Date | number, locale?: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* LocaleUtils — static utility for i18n message resolution.
|
|
194
|
+
*
|
|
195
|
+
* Provides convenient methods for resolving messages using the current locale
|
|
196
|
+
* context and a configured MessageSource.
|
|
197
|
+
*/
|
|
198
|
+
declare class LocaleUtils {
|
|
199
|
+
private static messageSource;
|
|
200
|
+
/**
|
|
201
|
+
* Set the global message source used by resolve helpers.
|
|
202
|
+
*/
|
|
203
|
+
static setMessageSource(source: MessageSource): void;
|
|
204
|
+
/**
|
|
205
|
+
* Get the currently configured global message source.
|
|
206
|
+
*/
|
|
207
|
+
static getMessageSource(): MessageSource | null;
|
|
208
|
+
/**
|
|
209
|
+
* Resolve a message using the current locale context.
|
|
210
|
+
*/
|
|
211
|
+
static resolveMessage(code: string, ...args: unknown[]): string;
|
|
212
|
+
/**
|
|
213
|
+
* Resolve a message with a default fallback using the current locale context.
|
|
214
|
+
*/
|
|
215
|
+
static resolveMessageWithDefault(code: string, defaultMessage: string, ...args: unknown[]): string;
|
|
216
|
+
/**
|
|
217
|
+
* Resolve a message using a specific MessageSource and the current locale.
|
|
218
|
+
*/
|
|
219
|
+
static resolveMessageFrom(source: MessageSource, code: string, defaultMessage?: string, ...args: unknown[]): string;
|
|
220
|
+
/**
|
|
221
|
+
* Resolve a message using a specific locale (ignoring the context locale).
|
|
222
|
+
*/
|
|
223
|
+
static resolveMessageForLocale(code: string, locale: string, defaultMessage?: string, ...args: unknown[]): string;
|
|
224
|
+
/**
|
|
225
|
+
* Execute a function within a specific locale context.
|
|
226
|
+
*/
|
|
227
|
+
static doWith<T>(locale: string, fn: () => T): T;
|
|
228
|
+
/**
|
|
229
|
+
* Execute an async function within a specific locale context.
|
|
230
|
+
*/
|
|
231
|
+
static doWithAsync<T>(locale: string, fn: () => Promise<T>): Promise<T>;
|
|
232
|
+
/**
|
|
233
|
+
* Get the current locale.
|
|
234
|
+
*/
|
|
235
|
+
static current(): string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @I18n(code) -- marks a field/property for i18n text resolution.
|
|
240
|
+
*
|
|
241
|
+
* When applied, the field value is treated as an i18n message code
|
|
242
|
+
* that should be resolved through the MessageSource at display time.
|
|
243
|
+
*/
|
|
244
|
+
declare function I18n(code: string): PropertyDecorator;
|
|
245
|
+
/**
|
|
246
|
+
* Get the i18n code associated with a property.
|
|
247
|
+
*/
|
|
248
|
+
declare function getI18nCode(target: object, propertyKey: string | symbol): string | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Check if a property has an i18n code.
|
|
251
|
+
*/
|
|
252
|
+
declare function hasI18n(target: object, propertyKey: string | symbol): boolean;
|
|
253
|
+
|
|
254
|
+
declare const MESSAGE_SOURCE = "MESSAGE_SOURCE";
|
|
255
|
+
interface I18nModuleOptions {
|
|
256
|
+
/** Path to message files directory */
|
|
257
|
+
basePath?: string;
|
|
258
|
+
/** Default locale */
|
|
259
|
+
defaultLocale?: string;
|
|
260
|
+
/** Supported locales */
|
|
261
|
+
supportedLocales?: string[];
|
|
262
|
+
/** Additional message sources */
|
|
263
|
+
messageSources?: MessageSource[];
|
|
264
|
+
}
|
|
265
|
+
interface I18nModuleAsyncOptions {
|
|
266
|
+
imports?: Array<Type | DynamicModule>;
|
|
267
|
+
useFactory?: (...args: unknown[]) => I18nModuleOptions | Promise<I18nModuleOptions>;
|
|
268
|
+
useClass?: Type<I18nModuleOptionsFactory>;
|
|
269
|
+
useExisting?: Type<I18nModuleOptionsFactory>;
|
|
270
|
+
inject?: Array<InjectionToken | OptionalFactoryDependency>;
|
|
271
|
+
}
|
|
272
|
+
interface I18nModuleOptionsFactory {
|
|
273
|
+
createI18nOptions(): I18nModuleOptions | Promise<I18nModuleOptions>;
|
|
274
|
+
}
|
|
275
|
+
declare class ZuckerI18nModule {
|
|
276
|
+
static forRoot(options?: I18nModuleOptions): DynamicModule;
|
|
277
|
+
static forRootAsync(options: I18nModuleAsyncOptions): DynamicModule;
|
|
278
|
+
private static buildProviders;
|
|
279
|
+
private static createAsyncProviders;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { CompositeMessageSource, FileMessageSource, I18n, I18nException, type I18nModuleAsyncOptions, type I18nModuleOptions, type I18nModuleOptionsFactory, I18nSpec, LocaleContext, LocaleInterceptor, LocaleUtils, MESSAGE_SOURCE, type MessageSource, ZuckerI18nModule, formatDate, formatMessage, formatNumber, formatRelativeTime, getI18nCode, hasI18n, pluralize };
|