@flyingrobots/bijou-i18n 7.2.0 → 8.0.0-rc.1
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/dist/localization.d.ts +3 -78
- package/dist/localization.d.ts.map +1 -1
- package/dist/localization.js +2 -180
- package/dist/localization.js.map +1 -1
- package/dist/localization.part01.d.ts +62 -0
- package/dist/localization.part01.d.ts.map +1 -0
- package/dist/localization.part01.js +26 -0
- package/dist/localization.part01.js.map +1 -0
- package/dist/localization.part02.d.ts +21 -0
- package/dist/localization.part02.d.ts.map +1 -0
- package/dist/localization.part02.js +96 -0
- package/dist/localization.part02.js.map +1 -0
- package/dist/localization.part03.d.ts +6 -0
- package/dist/localization.part03.d.ts.map +1 -0
- package/dist/localization.part03.js +64 -0
- package/dist/localization.part03.js.map +1 -0
- package/dist/runtime-catalog.d.ts +16 -0
- package/dist/runtime-catalog.d.ts.map +1 -0
- package/dist/runtime-catalog.js +112 -0
- package/dist/runtime-catalog.js.map +1 -0
- package/dist/runtime-contract.d.ts +64 -0
- package/dist/runtime-contract.d.ts.map +1 -0
- package/dist/runtime-contract.js +2 -0
- package/dist/runtime-contract.js.map +1 -0
- package/dist/runtime-create.d.ts +4 -0
- package/dist/runtime-create.d.ts.map +1 -0
- package/dist/runtime-create.js +108 -0
- package/dist/runtime-create.js.map +1 -0
- package/dist/runtime-format.d.ts +4 -0
- package/dist/runtime-format.d.ts.map +1 -0
- package/dist/runtime-format.js +48 -0
- package/dist/runtime-format.js.map +1 -0
- package/dist/runtime-localize.d.ts +5 -0
- package/dist/runtime-localize.d.ts.map +1 -0
- package/dist/runtime-localize.js +91 -0
- package/dist/runtime-localize.js.map +1 -0
- package/dist/runtime-resolution.d.ts +16 -0
- package/dist/runtime-resolution.d.ts.map +1 -0
- package/dist/runtime-resolution.js +79 -0
- package/dist/runtime-resolution.js.map +1 -0
- package/dist/runtime.d.ts +3 -62
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +2 -400
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/dist/localization.d.ts
CHANGED
|
@@ -1,79 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
readonly key: I18nCatalogKey;
|
|
5
|
-
readonly kind?: I18nEntryKind;
|
|
6
|
-
readonly values?: Readonly<Record<string, unknown>>;
|
|
7
|
-
}
|
|
8
|
-
export type LocalizationIssueCode = 'missing-key' | 'missing-locale' | 'kind-mismatch' | 'invalid-message-value';
|
|
9
|
-
export interface LocalizationIssue {
|
|
10
|
-
readonly code: LocalizationIssueCode;
|
|
11
|
-
readonly key: I18nCatalogKey;
|
|
12
|
-
readonly locale: string;
|
|
13
|
-
readonly fallbackLocale: string;
|
|
14
|
-
readonly message: string;
|
|
15
|
-
}
|
|
16
|
-
export type LocalizationFactKind = 'locale' | 'direction' | 'localization-status' | 'entry-kind';
|
|
17
|
-
export interface LocalizationFact {
|
|
18
|
-
readonly kind: LocalizationFactKind;
|
|
19
|
-
readonly key: string;
|
|
20
|
-
readonly value: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Structured localization result returned by a {@link LocalizationPort}.
|
|
24
|
-
*
|
|
25
|
-
* Values are expected to be JSON-shaped boundary payloads: plain objects,
|
|
26
|
-
* arrays, scalars, or nullish values. Symbol-keyed properties, non-enumerable
|
|
27
|
-
* properties, cyclic graphs, class instances, and accessors are outside the
|
|
28
|
-
* portable catalog contract; accessors are rejected when plain objects cross
|
|
29
|
-
* the freeze boundary.
|
|
30
|
-
*/
|
|
31
|
-
export interface LocalizedObject<Value = unknown> {
|
|
32
|
-
readonly key: I18nCatalogKey;
|
|
33
|
-
readonly locale: string;
|
|
34
|
-
readonly fallbackLocale: string;
|
|
35
|
-
readonly sourceLocale?: string;
|
|
36
|
-
readonly direction: I18nDirection;
|
|
37
|
-
readonly kind: I18nEntryKind;
|
|
38
|
-
readonly status: LocalizationStatus;
|
|
39
|
-
readonly value?: Value;
|
|
40
|
-
readonly issues: readonly LocalizationIssue[];
|
|
41
|
-
readonly facts: readonly LocalizationFact[];
|
|
42
|
-
}
|
|
43
|
-
export interface LocalizationPort {
|
|
44
|
-
readonly locale: string;
|
|
45
|
-
readonly direction: I18nDirection;
|
|
46
|
-
resolve(request: LocalizationRequest): LocalizedObject;
|
|
47
|
-
formatNumber(value: number): string;
|
|
48
|
-
formatDate(value: Date): string;
|
|
49
|
-
formatTime(value: Date): string;
|
|
50
|
-
formatList(values: readonly string[]): string;
|
|
51
|
-
}
|
|
52
|
-
export interface RuntimeLocalizationPortSource {
|
|
53
|
-
readonly locale: string;
|
|
54
|
-
readonly direction: I18nDirection;
|
|
55
|
-
localize(request: LocalizationRequest): LocalizedObject;
|
|
56
|
-
formatNumber(value: number, locale: string): string;
|
|
57
|
-
formatDate(value: Date, locale: string): string;
|
|
58
|
-
formatTime(value: Date, locale: string): string;
|
|
59
|
-
formatList(values: readonly string[], locale: string): string;
|
|
60
|
-
}
|
|
61
|
-
export declare function createRuntimeLocalizationPort(runtime: RuntimeLocalizationPortSource): LocalizationPort;
|
|
62
|
-
export declare function freezeLocalizedObject<Value>(object: LocalizedObject<Value>): LocalizedObject<Value>;
|
|
63
|
-
/**
|
|
64
|
-
* Deep-freeze a JSON-shaped localized value.
|
|
65
|
-
*
|
|
66
|
-
* This helper intentionally preserves the portable catalog contract rather
|
|
67
|
-
* than arbitrary JavaScript object identity. Plain objects must expose data
|
|
68
|
-
* properties only; accessor-backed plain objects are rejected.
|
|
69
|
-
*/
|
|
70
|
-
export declare function freezeLocalizedValue<Value>(value: Value): Value;
|
|
71
|
-
/**
|
|
72
|
-
* Check whether a value can cross the localization resource/data boundary.
|
|
73
|
-
*
|
|
74
|
-
* This performs the same validation as {@link freezeLocalizedValue} without
|
|
75
|
-
* exposing the frozen clone. Adapter code can use it to reject non-portable
|
|
76
|
-
* payloads before constructing catalogs.
|
|
77
|
-
*/
|
|
78
|
-
export declare function isJsonShapedLocalizedValue(value: unknown): boolean;
|
|
1
|
+
export type { LocalizationStatus, LocalizationRequest, LocalizationIssueCode, LocalizationIssue, LocalizationFactKind, LocalizationFact, LocalizedObject, LocalizationPort, RuntimeLocalizationPortSource, } from './localization.part01.js';
|
|
2
|
+
export { createRuntimeLocalizationPort } from './localization.part01.js';
|
|
3
|
+
export { freezeLocalizedObject, freezeLocalizedValue, isJsonShapedLocalizedValue, } from './localization.part02.js';
|
|
79
4
|
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC"}
|
package/dist/localization.js
CHANGED
|
@@ -1,181 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
get locale() {
|
|
4
|
-
return runtime.locale;
|
|
5
|
-
},
|
|
6
|
-
get direction() {
|
|
7
|
-
return runtime.direction;
|
|
8
|
-
},
|
|
9
|
-
resolve(request) {
|
|
10
|
-
return runtime.localize(request);
|
|
11
|
-
},
|
|
12
|
-
formatNumber(value) {
|
|
13
|
-
return runtime.formatNumber(value, runtime.locale);
|
|
14
|
-
},
|
|
15
|
-
formatDate(value) {
|
|
16
|
-
return runtime.formatDate(value, runtime.locale);
|
|
17
|
-
},
|
|
18
|
-
formatTime(value) {
|
|
19
|
-
return runtime.formatTime(value, runtime.locale);
|
|
20
|
-
},
|
|
21
|
-
formatList(values) {
|
|
22
|
-
return runtime.formatList(values, runtime.locale);
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export function freezeLocalizedObject(object) {
|
|
27
|
-
return Object.freeze({
|
|
28
|
-
...object,
|
|
29
|
-
key: Object.freeze({ ...object.key }),
|
|
30
|
-
value: freezeLocalizedValue(object.value),
|
|
31
|
-
issues: Object.freeze(object.issues.map((issue) => Object.freeze({
|
|
32
|
-
...issue,
|
|
33
|
-
key: Object.freeze({ ...issue.key }),
|
|
34
|
-
}))),
|
|
35
|
-
facts: Object.freeze(object.facts.map((fact) => Object.freeze({ ...fact }))),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Deep-freeze a JSON-shaped localized value.
|
|
40
|
-
*
|
|
41
|
-
* This helper intentionally preserves the portable catalog contract rather
|
|
42
|
-
* than arbitrary JavaScript object identity. Plain objects must expose data
|
|
43
|
-
* properties only; accessor-backed plain objects are rejected.
|
|
44
|
-
*/
|
|
45
|
-
export function freezeLocalizedValue(value) {
|
|
46
|
-
validateLocalizedValue(value, 'value', new WeakSet());
|
|
47
|
-
const clone = structuredClone(value);
|
|
48
|
-
freezeLocalizedClone(clone, new WeakSet());
|
|
49
|
-
return clone;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Check whether a value can cross the localization resource/data boundary.
|
|
53
|
-
*
|
|
54
|
-
* This performs the same validation as {@link freezeLocalizedValue} without
|
|
55
|
-
* exposing the frozen clone. Adapter code can use it to reject non-portable
|
|
56
|
-
* payloads before constructing catalogs.
|
|
57
|
-
*/
|
|
58
|
-
export function isJsonShapedLocalizedValue(value) {
|
|
59
|
-
try {
|
|
60
|
-
freezeLocalizedValue(value);
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function validateLocalizedValue(value, path, seen) {
|
|
68
|
-
if (value == null || typeof value !== 'object') {
|
|
69
|
-
if (typeof value === 'bigint' || typeof value === 'symbol' || typeof value === 'function') {
|
|
70
|
-
throw new Error(`Localized value contains unsupported ${typeof value} at ${path}`);
|
|
71
|
-
}
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const objectValue = value;
|
|
75
|
-
if (seen.has(objectValue)) {
|
|
76
|
-
throw new Error(`Localized value contains circular reference at ${path}`);
|
|
77
|
-
}
|
|
78
|
-
seen.add(objectValue);
|
|
79
|
-
try {
|
|
80
|
-
validateLocalizedObjectValue(value, path, seen);
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
seen.delete(objectValue);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function validateLocalizedObjectValue(value, path, seen) {
|
|
87
|
-
if (Array.isArray(value)) {
|
|
88
|
-
validateLocalizedArray(value, path);
|
|
89
|
-
for (const [index, item] of value.entries()) {
|
|
90
|
-
validateLocalizedValue(item, `${path}[${String(index)}]`, seen);
|
|
91
|
-
}
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const prototype = Object.getPrototypeOf(value);
|
|
95
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
96
|
-
throw new Error(`Localized value contains unsupported ${objectKind(value)} at ${path}`);
|
|
97
|
-
}
|
|
98
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
99
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
100
|
-
if (typeof key === 'symbol') {
|
|
101
|
-
throw new Error(`Localized value contains unsupported symbol property at ${path}`);
|
|
102
|
-
}
|
|
103
|
-
const descriptor = descriptors[key];
|
|
104
|
-
if (descriptor === undefined) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
const propertyPath = `${path}.${key}`;
|
|
108
|
-
if (!descriptor.enumerable) {
|
|
109
|
-
throw new Error(`Localized value contains unsupported non-enumerable property: ${propertyPath}`);
|
|
110
|
-
}
|
|
111
|
-
if (!('value' in descriptor)) {
|
|
112
|
-
throw new Error(`Localized value contains unsupported accessor property: ${propertyPath}`);
|
|
113
|
-
}
|
|
114
|
-
const descriptorValue = descriptor.value;
|
|
115
|
-
validateLocalizedValue(descriptorValue, propertyPath, seen);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function validateLocalizedArray(value, path) {
|
|
119
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
120
|
-
let indexedPropertyCount = 0;
|
|
121
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
122
|
-
if (typeof key === 'symbol') {
|
|
123
|
-
throw new Error(`Localized value contains unsupported symbol property at ${path}`);
|
|
124
|
-
}
|
|
125
|
-
if (key === 'length') {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
const descriptor = descriptors[key];
|
|
129
|
-
if (descriptor === undefined) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
const propertyPath = arrayPropertyPath(path, key);
|
|
133
|
-
if (!descriptor.enumerable) {
|
|
134
|
-
throw new Error(`Localized value contains unsupported non-enumerable property: ${propertyPath}`);
|
|
135
|
-
}
|
|
136
|
-
if (!('value' in descriptor)) {
|
|
137
|
-
throw new Error(`Localized value contains unsupported accessor property: ${propertyPath}`);
|
|
138
|
-
}
|
|
139
|
-
if (!isArrayIndexKey(key)) {
|
|
140
|
-
throw new Error(`Localized value contains unsupported array property: ${propertyPath}`);
|
|
141
|
-
}
|
|
142
|
-
indexedPropertyCount += 1;
|
|
143
|
-
}
|
|
144
|
-
if (indexedPropertyCount !== value.length) {
|
|
145
|
-
throw new Error(`Localized value contains unsupported sparse array at ${path}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
function arrayPropertyPath(path, key) {
|
|
149
|
-
return isArrayIndexKey(key) ? `${path}[${key}]` : `${path}.${key}`;
|
|
150
|
-
}
|
|
151
|
-
function isArrayIndexKey(key) {
|
|
152
|
-
if (key === '') {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
const index = Number(key);
|
|
156
|
-
return Number.isInteger(index)
|
|
157
|
-
&& index >= 0
|
|
158
|
-
&& index < 2 ** 32 - 1
|
|
159
|
-
&& String(index) === key;
|
|
160
|
-
}
|
|
161
|
-
function objectKind(value) {
|
|
162
|
-
return Object.prototype.toString.call(value).slice(8, -1);
|
|
163
|
-
}
|
|
164
|
-
function freezeLocalizedClone(value, seen) {
|
|
165
|
-
if (value == null || typeof value !== 'object') {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (seen.has(value)) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
seen.add(value);
|
|
172
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
173
|
-
for (const descriptor of Object.values(descriptors)) {
|
|
174
|
-
if ('value' in descriptor) {
|
|
175
|
-
const descriptorValue = descriptor.value;
|
|
176
|
-
freezeLocalizedClone(descriptorValue, seen);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
Object.freeze(value);
|
|
180
|
-
}
|
|
1
|
+
export { createRuntimeLocalizationPort } from './localization.part01.js';
|
|
2
|
+
export { freezeLocalizedObject, freezeLocalizedValue, isJsonShapedLocalizedValue, } from './localization.part02.js';
|
|
181
3
|
//# sourceMappingURL=localization.js.map
|
package/dist/localization.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { I18nCatalogKey, I18nDirection, I18nEntryKind } from './runtime.js';
|
|
2
|
+
export type LocalizationStatus = 'translated' | 'fallback' | 'missing';
|
|
3
|
+
export interface LocalizationRequest {
|
|
4
|
+
readonly key: I18nCatalogKey;
|
|
5
|
+
readonly kind?: I18nEntryKind;
|
|
6
|
+
readonly values?: Readonly<Record<string, unknown>>;
|
|
7
|
+
}
|
|
8
|
+
export type LocalizationIssueCode = 'missing-key' | 'missing-locale' | 'kind-mismatch' | 'invalid-message-value';
|
|
9
|
+
export interface LocalizationIssue {
|
|
10
|
+
readonly code: LocalizationIssueCode;
|
|
11
|
+
readonly key: I18nCatalogKey;
|
|
12
|
+
readonly locale: string;
|
|
13
|
+
readonly fallbackLocale: string;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
}
|
|
16
|
+
export type LocalizationFactKind = 'locale' | 'direction' | 'localization-status' | 'entry-kind';
|
|
17
|
+
export interface LocalizationFact {
|
|
18
|
+
readonly kind: LocalizationFactKind;
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly value: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Structured localization result returned by a {@link LocalizationPort}.
|
|
24
|
+
*
|
|
25
|
+
* Values are expected to be JSON-shaped boundary payloads: plain objects,
|
|
26
|
+
* arrays, scalars, or nullish values. Symbol-keyed properties, non-enumerable
|
|
27
|
+
* properties, cyclic graphs, class instances, and accessors are outside the
|
|
28
|
+
* portable catalog contract; accessors are rejected when plain objects cross
|
|
29
|
+
* the freeze boundary.
|
|
30
|
+
*/
|
|
31
|
+
export interface LocalizedObject<Value = unknown> {
|
|
32
|
+
readonly key: I18nCatalogKey;
|
|
33
|
+
readonly locale: string;
|
|
34
|
+
readonly fallbackLocale: string;
|
|
35
|
+
readonly sourceLocale?: string;
|
|
36
|
+
readonly direction: I18nDirection;
|
|
37
|
+
readonly kind: I18nEntryKind;
|
|
38
|
+
readonly status: LocalizationStatus;
|
|
39
|
+
readonly value?: Value;
|
|
40
|
+
readonly issues: readonly LocalizationIssue[];
|
|
41
|
+
readonly facts: readonly LocalizationFact[];
|
|
42
|
+
}
|
|
43
|
+
export interface LocalizationPort {
|
|
44
|
+
readonly locale: string;
|
|
45
|
+
readonly direction: I18nDirection;
|
|
46
|
+
resolve(request: LocalizationRequest): LocalizedObject;
|
|
47
|
+
formatNumber(value: number): string;
|
|
48
|
+
formatDate(value: Date): string;
|
|
49
|
+
formatTime(value: Date): string;
|
|
50
|
+
formatList(values: readonly string[]): string;
|
|
51
|
+
}
|
|
52
|
+
export interface RuntimeLocalizationPortSource {
|
|
53
|
+
readonly locale: string;
|
|
54
|
+
readonly direction: I18nDirection;
|
|
55
|
+
localize(request: LocalizationRequest): LocalizedObject;
|
|
56
|
+
formatNumber(value: number, locale: string): string;
|
|
57
|
+
formatDate(value: Date, locale: string): string;
|
|
58
|
+
formatTime(value: Date, locale: string): string;
|
|
59
|
+
formatList(values: readonly string[], locale: string): string;
|
|
60
|
+
}
|
|
61
|
+
export declare function createRuntimeLocalizationPort(runtime: RuntimeLocalizationPortSource): LocalizationPort;
|
|
62
|
+
//# sourceMappingURL=localization.part01.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.part01.d.ts","sourceRoot":"","sources":["../src/localization.part01.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;AACvE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD;AACD,MAAM,MAAM,qBAAqB,GAC/B,aAAa,GAAG,gBAAgB,GAAG,eAAe,GAAG,uBAAuB,CAA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;IACvD,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAAC;IAChC,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAAC;IAChC,UAAU,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;CAC/C;AACD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,eAAe,CAAC;IACxD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACpD,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAChD,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAChD,UAAU,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/D;AACD,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,6BAA6B,GACrC,gBAAgB,CAwBlB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function createRuntimeLocalizationPort(runtime) {
|
|
2
|
+
return Object.freeze({
|
|
3
|
+
get locale() {
|
|
4
|
+
return runtime.locale;
|
|
5
|
+
},
|
|
6
|
+
get direction() {
|
|
7
|
+
return runtime.direction;
|
|
8
|
+
},
|
|
9
|
+
resolve(request) {
|
|
10
|
+
return runtime.localize(request);
|
|
11
|
+
},
|
|
12
|
+
formatNumber(value) {
|
|
13
|
+
return runtime.formatNumber(value, runtime.locale);
|
|
14
|
+
},
|
|
15
|
+
formatDate(value) {
|
|
16
|
+
return runtime.formatDate(value, runtime.locale);
|
|
17
|
+
},
|
|
18
|
+
formatTime(value) {
|
|
19
|
+
return runtime.formatTime(value, runtime.locale);
|
|
20
|
+
},
|
|
21
|
+
formatList(values) {
|
|
22
|
+
return runtime.formatList(values, runtime.locale);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=localization.part01.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.part01.js","sourceRoot":"","sources":["../src/localization.part01.ts"],"names":[],"mappings":"AAmEA,MAAM,UAAU,6BAA6B,CAC3C,OAAsC;IAEtC,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,MAAM;YACR,OAAO,OAAO,CAAC,MAAM,CAAC;QACxB,CAAC;QACD,IAAI,SAAS;YACX,OAAO,OAAO,CAAC,SAAS,CAAC;QAC3B,CAAC;QACD,OAAO,CAAC,OAA4B;YAClC,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QACD,YAAY,CAAC,KAAa;YACxB,OAAO,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;QACD,UAAU,CAAC,KAAW;YACpB,OAAO,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;QACD,UAAU,CAAC,KAAW;YACpB,OAAO,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;QACD,UAAU,CAAC,MAAyB;YAClC,OAAO,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type LocalizedObject } from './localization.part01.js';
|
|
2
|
+
export declare function freezeLocalizedObject<Value>(object: LocalizedObject<Value>): LocalizedObject<Value>;
|
|
3
|
+
/**
|
|
4
|
+
* Deep-freeze a JSON-shaped localized value.
|
|
5
|
+
*
|
|
6
|
+
* This helper intentionally preserves the portable catalog contract rather
|
|
7
|
+
* than arbitrary JavaScript object identity. Plain objects must expose data
|
|
8
|
+
* properties only; accessor-backed plain objects are rejected.
|
|
9
|
+
*/
|
|
10
|
+
export declare function freezeLocalizedValue<Value>(value: Value): Value;
|
|
11
|
+
/**
|
|
12
|
+
* Check whether a value can cross the localization resource/data boundary.
|
|
13
|
+
*
|
|
14
|
+
* This performs the same validation as {@link freezeLocalizedValue} without
|
|
15
|
+
* exposing the frozen clone. Adapter code can use it to reject non-portable
|
|
16
|
+
* payloads before constructing catalogs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isJsonShapedLocalizedValue(value: unknown): boolean;
|
|
19
|
+
export declare function validateLocalizedValue(value: unknown, path: string, seen: WeakSet<object>): void;
|
|
20
|
+
export declare function validateLocalizedObjectValue(value: object, path: string, seen: WeakSet<object>): void;
|
|
21
|
+
//# sourceMappingURL=localization.part02.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.part02.d.ts","sourceRoot":"","sources":["../src/localization.part02.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAOhE,wBAAgB,qBAAqB,CAAC,KAAK,EACzC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,GAC7B,eAAe,CAAC,KAAK,CAAC,CAiBxB;AACD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAK/D;AACD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOlE;AACD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,GACpB,IAAI,CAyBN;AACD,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,GACpB,IAAI,CA0CN"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { freezeLocalizedClone, objectKind, validateLocalizedArray, } from './localization.part03.js';
|
|
2
|
+
export function freezeLocalizedObject(object) {
|
|
3
|
+
return Object.freeze({
|
|
4
|
+
...object,
|
|
5
|
+
key: Object.freeze({ ...object.key }),
|
|
6
|
+
value: freezeLocalizedValue(object.value),
|
|
7
|
+
issues: Object.freeze(object.issues.map((issue) => Object.freeze({
|
|
8
|
+
...issue,
|
|
9
|
+
key: Object.freeze({ ...issue.key }),
|
|
10
|
+
}))),
|
|
11
|
+
facts: Object.freeze(object.facts.map((fact) => Object.freeze({ ...fact }))),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Deep-freeze a JSON-shaped localized value.
|
|
16
|
+
*
|
|
17
|
+
* This helper intentionally preserves the portable catalog contract rather
|
|
18
|
+
* than arbitrary JavaScript object identity. Plain objects must expose data
|
|
19
|
+
* properties only; accessor-backed plain objects are rejected.
|
|
20
|
+
*/
|
|
21
|
+
export function freezeLocalizedValue(value) {
|
|
22
|
+
validateLocalizedValue(value, 'value', new WeakSet());
|
|
23
|
+
const clone = structuredClone(value);
|
|
24
|
+
freezeLocalizedClone(clone, new WeakSet());
|
|
25
|
+
return clone;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check whether a value can cross the localization resource/data boundary.
|
|
29
|
+
*
|
|
30
|
+
* This performs the same validation as {@link freezeLocalizedValue} without
|
|
31
|
+
* exposing the frozen clone. Adapter code can use it to reject non-portable
|
|
32
|
+
* payloads before constructing catalogs.
|
|
33
|
+
*/
|
|
34
|
+
export function isJsonShapedLocalizedValue(value) {
|
|
35
|
+
try {
|
|
36
|
+
freezeLocalizedValue(value);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function validateLocalizedValue(value, path, seen) {
|
|
44
|
+
if (value == null || typeof value !== 'object') {
|
|
45
|
+
if (typeof value === 'bigint' ||
|
|
46
|
+
typeof value === 'symbol' ||
|
|
47
|
+
typeof value === 'function') {
|
|
48
|
+
throw new Error(`Localized value contains unsupported ${typeof value} at ${path}`);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const objectValue = value;
|
|
53
|
+
if (seen.has(objectValue)) {
|
|
54
|
+
throw new Error(`Localized value contains circular reference at ${path}`);
|
|
55
|
+
}
|
|
56
|
+
seen.add(objectValue);
|
|
57
|
+
try {
|
|
58
|
+
validateLocalizedObjectValue(value, path, seen);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
seen.delete(objectValue);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function validateLocalizedObjectValue(value, path, seen) {
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
validateLocalizedArray(value, path);
|
|
67
|
+
for (const [index, item] of value.entries()) {
|
|
68
|
+
validateLocalizedValue(item, `${path}[${String(index)}]`, seen);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const prototype = Object.getPrototypeOf(value);
|
|
73
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
74
|
+
throw new Error(`Localized value contains unsupported ${objectKind(value)} at ${path}`);
|
|
75
|
+
}
|
|
76
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
77
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
78
|
+
if (typeof key === 'symbol') {
|
|
79
|
+
throw new Error(`Localized value contains unsupported symbol property at ${path}`);
|
|
80
|
+
}
|
|
81
|
+
const descriptor = descriptors[key];
|
|
82
|
+
if (descriptor === undefined) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const propertyPath = `${path}.${key}`;
|
|
86
|
+
if (!descriptor.enumerable) {
|
|
87
|
+
throw new Error(`Localized value contains unsupported non-enumerable property: ${propertyPath}`);
|
|
88
|
+
}
|
|
89
|
+
if (!('value' in descriptor)) {
|
|
90
|
+
throw new Error(`Localized value contains unsupported accessor property: ${propertyPath}`);
|
|
91
|
+
}
|
|
92
|
+
const descriptorValue = descriptor.value;
|
|
93
|
+
validateLocalizedValue(descriptorValue, propertyPath, seen);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=localization.part02.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.part02.js","sourceRoot":"","sources":["../src/localization.part02.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,UAAU,qBAAqB,CACnC,MAA8B;IAE9B,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,MAAM;QACT,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QACrC,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC;QACzC,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC1B,MAAM,CAAC,MAAM,CAAC;YACZ,GAAG,KAAK;YACR,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;SACrC,CAAC,CACH,CACF;QACD,KAAK,EAAE,MAAM,CAAC,MAAM,CAClB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CACvD;KACF,CAAC,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F,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,CAAC,OAAO,IAAI,UAAU,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,2DAA2D,YAAY,EAAE,CAC1E,CAAC;QACJ,CAAC;QACD,MAAM,eAAe,GAAY,UAAU,CAAC,KAAK,CAAC;QAClD,sBAAsB,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function validateLocalizedArray(value: readonly unknown[], path: string): void;
|
|
2
|
+
export declare function arrayPropertyPath(path: string, key: string): string;
|
|
3
|
+
export declare function isArrayIndexKey(key: string): boolean;
|
|
4
|
+
export declare function objectKind(value: object): string;
|
|
5
|
+
export declare function freezeLocalizedClone(value: unknown, seen: WeakSet<object>): void;
|
|
6
|
+
//# sourceMappingURL=localization.part03.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.part03.d.ts","sourceRoot":"","sources":["../src/localization.part03.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,IAAI,EAAE,MAAM,GACX,IAAI,CA2CN;AACD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnE;AACD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAWpD;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AACD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,GACpB,IAAI,CAmBN"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export function validateLocalizedArray(value, path) {
|
|
2
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
3
|
+
let indexedPropertyCount = 0;
|
|
4
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
5
|
+
if (typeof key === 'symbol') {
|
|
6
|
+
throw new Error(`Localized value contains unsupported symbol property at ${path}`);
|
|
7
|
+
}
|
|
8
|
+
if (key === 'length') {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const descriptor = descriptors[key];
|
|
12
|
+
if (descriptor === undefined) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const propertyPath = arrayPropertyPath(path, key);
|
|
16
|
+
if (!descriptor.enumerable) {
|
|
17
|
+
throw new Error(`Localized value contains unsupported non-enumerable property: ${propertyPath}`);
|
|
18
|
+
}
|
|
19
|
+
if (!('value' in descriptor)) {
|
|
20
|
+
throw new Error(`Localized value contains unsupported accessor property: ${propertyPath}`);
|
|
21
|
+
}
|
|
22
|
+
if (!isArrayIndexKey(key)) {
|
|
23
|
+
throw new Error(`Localized value contains unsupported array property: ${propertyPath}`);
|
|
24
|
+
}
|
|
25
|
+
indexedPropertyCount += 1;
|
|
26
|
+
}
|
|
27
|
+
if (indexedPropertyCount !== value.length) {
|
|
28
|
+
throw new Error(`Localized value contains unsupported sparse array at ${path}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function arrayPropertyPath(path, key) {
|
|
32
|
+
return isArrayIndexKey(key) ? `${path}[${key}]` : `${path}.${key}`;
|
|
33
|
+
}
|
|
34
|
+
export function isArrayIndexKey(key) {
|
|
35
|
+
if (key === '') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const index = Number(key);
|
|
39
|
+
return (Number.isInteger(index) &&
|
|
40
|
+
index >= 0 &&
|
|
41
|
+
index < 2 ** 32 - 1 &&
|
|
42
|
+
String(index) === key);
|
|
43
|
+
}
|
|
44
|
+
export function objectKind(value) {
|
|
45
|
+
return Object.prototype.toString.call(value).slice(8, -1);
|
|
46
|
+
}
|
|
47
|
+
export function freezeLocalizedClone(value, seen) {
|
|
48
|
+
if (value == null || typeof value !== 'object') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (seen.has(value)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
seen.add(value);
|
|
55
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
56
|
+
for (const descriptor of Object.values(descriptors)) {
|
|
57
|
+
if ('value' in descriptor) {
|
|
58
|
+
const descriptorValue = descriptor.value;
|
|
59
|
+
freezeLocalizedClone(descriptorValue, seen);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Object.freeze(value);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=localization.part03.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.part03.js","sourceRoot":"","sources":["../src/localization.part03.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB,CACpC,KAAyB,EACzB,IAAY;IAEZ,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAC5D,IAAI,oBAAoB,GAAG,CAAC,CAAC;IAC7B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/C,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,2DAA2D,IAAI,EAAE,CAClE,CAAC;QACJ,CAAC;QAED,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,SAAS;QACX,CAAC;QAED,MAAM,YAAY,GAAG,iBAAiB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,iEAAiE,YAAY,EAAE,CA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KAAc,EACd,IAAqB;IAErB,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/C,OAAO;IACT,CAAC;IAED,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEhB,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAC5D,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACpD,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;YAC1B,MAAM,eAAe,GAAY,UAAU,CAAC,KAAK,CAAC;YAClD,oBAAoB,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { I18nCatalog, I18nCatalogEntry, I18nCatalogKey, I18nReference, I18nRuntimeOptions } from './runtime-contract.js';
|
|
2
|
+
export declare class RuntimeCatalogStore {
|
|
3
|
+
#private;
|
|
4
|
+
readonly entries: Map<string, I18nCatalogEntry<unknown>>;
|
|
5
|
+
constructor(options: I18nRuntimeOptions);
|
|
6
|
+
loadCatalog(catalog: I18nCatalog): void;
|
|
7
|
+
loadCatalogs(catalogs: readonly I18nCatalog[]): void;
|
|
8
|
+
unloadCatalog(namespace: string): void;
|
|
9
|
+
preloadLocale(locale: string): Promise<void>;
|
|
10
|
+
localeCatalogs(locale: string): Promise<readonly I18nCatalog[] | undefined>;
|
|
11
|
+
activateLoaderCatalogs(catalogs: readonly I18nCatalog[]): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function keyToString(key: I18nCatalogKey): string;
|
|
14
|
+
export declare function isReference(value: unknown): value is I18nReference;
|
|
15
|
+
export declare function ref(key: I18nCatalogKey): I18nReference;
|
|
16
|
+
//# sourceMappingURL=runtime-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-catalog.d.ts","sourceRoot":"","sources":["../src/runtime-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EAEd,aAAa,EACb,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,mBAAmB;;IAC9B,QAAQ,CAAC,OAAO,yCAAuC;gBAO3C,OAAO,EAAE,kBAAkB;IAOvC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAKvC,YAAY,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI;IAKpD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAMhC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAe5C,cAAc,CAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,WAAW,EAAE,GAAG,SAAS,CAAC;IAM9C,sBAAsB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI;CAkD/D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAEvD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAMlE;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,aAAa,CAEtD"}
|