@flyingrobots/bijou-i18n 4.4.1 → 7.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/README.md +179 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/localization.d.ts +79 -0
- package/dist/localization.d.ts.map +1 -0
- package/dist/localization.js +159 -0
- package/dist/localization.js.map +1 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +298 -44
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,9 +10,188 @@ The in-memory localization runtime for Bijou.
|
|
|
10
10
|
- generic resource lookup
|
|
11
11
|
- runtime-safe references
|
|
12
12
|
- locale-aware formatting seams
|
|
13
|
+
- explicit fallback catalogs
|
|
14
|
+
- injectable missing-localization message formatting
|
|
15
|
+
- async locale loader support for runtime-integrated catalog activation
|
|
16
|
+
- an application-facing `LocalizationPort` that resolves structured localized
|
|
17
|
+
objects
|
|
18
|
+
- `isJsonShapedLocalizedValue()` for adapter-side resource/data payload
|
|
19
|
+
conformance checks
|
|
13
20
|
|
|
14
21
|
This package is intentionally runtime-only. Spreadsheet workflows, stale detection, pseudo-localization, and catalog compilation belong in `@flyingrobots/bijou-i18n-tools`.
|
|
15
22
|
|
|
23
|
+
## Loader Seam
|
|
24
|
+
|
|
25
|
+
Use `createI18nRuntime()` for fully preloaded catalogs, or
|
|
26
|
+
`createI18nRuntimeAsync()` when catalogs need to be loaded lazily:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { createI18nRuntimeAsync, type I18nCatalogLoader } from '@flyingrobots/bijou-i18n';
|
|
30
|
+
|
|
31
|
+
const loader: I18nCatalogLoader = async (locale) => {
|
|
32
|
+
const module = await import(`./catalogs/${locale}.js`);
|
|
33
|
+
return module.catalogs;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const runtime = await createI18nRuntimeAsync({
|
|
37
|
+
locale: 'fr',
|
|
38
|
+
direction: 'ltr',
|
|
39
|
+
loader,
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
When runtime payloads are generated as pure per-locale catalogs, load the source
|
|
44
|
+
or fallback catalog separately:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createI18nRuntime } from '@flyingrobots/bijou-i18n';
|
|
48
|
+
|
|
49
|
+
const runtime = createI18nRuntime({
|
|
50
|
+
locale: 'fr',
|
|
51
|
+
direction: 'ltr',
|
|
52
|
+
fallbackLocale: 'en',
|
|
53
|
+
fallbackCatalogs: [englishCatalog],
|
|
54
|
+
catalogs: [frenchCatalog],
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Production apps can use fallback catalogs for readable missing translations.
|
|
59
|
+
Development apps can inject `missingMessage` to render a loud marker instead of
|
|
60
|
+
quietly falling back when the selected locale is missing a string:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const runtime = createI18nRuntime({
|
|
64
|
+
locale: 'fr',
|
|
65
|
+
direction: 'ltr',
|
|
66
|
+
fallbackLocale: 'en',
|
|
67
|
+
fallbackCatalogs: [englishCatalog],
|
|
68
|
+
missingMessage: ({ key }) => `<MISSING LOC STRING KEY=${key.namespace}:${key.id}>`,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The same loader seam also supports file-backed locale bundles through
|
|
73
|
+
`@flyingrobots/bijou-i18n-tools-node`:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { createI18nRuntimeAsync } from '@flyingrobots/bijou-i18n';
|
|
77
|
+
import { createCatalogBundleFileLoader } from '@flyingrobots/bijou-i18n-tools-node';
|
|
78
|
+
|
|
79
|
+
const runtime = await createI18nRuntimeAsync({
|
|
80
|
+
locale: 'fr',
|
|
81
|
+
direction: 'ltr',
|
|
82
|
+
loader: createCatalogBundleFileLoader({
|
|
83
|
+
resolvePath: (locale) => `./i18n/${locale}.json`,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Once created, the runtime can preload and activate locales explicitly:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
await runtime.preloadLocale('de');
|
|
92
|
+
await runtime.setLocale('de');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Localization Port
|
|
96
|
+
|
|
97
|
+
Use `LocalizationPort` at application and view boundaries when callers need a
|
|
98
|
+
localized object instead of a concrete runtime:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import {
|
|
102
|
+
createI18nRuntime,
|
|
103
|
+
createRuntimeLocalizationPort,
|
|
104
|
+
} from '@flyingrobots/bijou-i18n';
|
|
105
|
+
|
|
106
|
+
const runtime = createI18nRuntime({
|
|
107
|
+
locale: 'fr',
|
|
108
|
+
direction: 'ltr',
|
|
109
|
+
fallbackLocale: 'en',
|
|
110
|
+
fallbackCatalogs: [englishCatalog],
|
|
111
|
+
catalogs: [frenchCatalog],
|
|
112
|
+
});
|
|
113
|
+
const localization = createRuntimeLocalizationPort(runtime);
|
|
114
|
+
|
|
115
|
+
const title = localization.resolve<string>({
|
|
116
|
+
key: { namespace: 'app', id: 'title' },
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`resolve()` returns a frozen localized object with the key, locale, direction,
|
|
121
|
+
entry kind, translated/fallback/missing status, value, issues, and facts. That
|
|
122
|
+
keeps rendering code away from catalog loading, filesystem paths, CSV data, and
|
|
123
|
+
runtime mutation details while preserving enough state for tooling and lower
|
|
124
|
+
modes.
|
|
125
|
+
|
|
126
|
+
## Resource And Data Payloads
|
|
127
|
+
|
|
128
|
+
Message entries resolve to strings. `resource` and `data` entries resolve to
|
|
129
|
+
portable structured values, and the runtime freezes those values before handing
|
|
130
|
+
them to callers.
|
|
131
|
+
|
|
132
|
+
Keep resource/data payloads JSON-shaped:
|
|
133
|
+
|
|
134
|
+
- strings, numbers, booleans, null, and undefined
|
|
135
|
+
- arrays with indexed entries only
|
|
136
|
+
- plain objects with enumerable data properties only
|
|
137
|
+
|
|
138
|
+
Do not use:
|
|
139
|
+
|
|
140
|
+
- class instances or built-ins such as `Date`
|
|
141
|
+
- symbol-keyed properties
|
|
142
|
+
- non-enumerable properties
|
|
143
|
+
- accessor properties
|
|
144
|
+
- cyclic object graphs
|
|
145
|
+
- functions, symbols, or bigint values
|
|
146
|
+
|
|
147
|
+
Unsupported shapes are rejected at the localization boundary rather than being
|
|
148
|
+
silently normalized. This keeps generated catalogs, runtime loader adapters, and
|
|
149
|
+
view code honest: adapters must produce portable data, and consumers can trust
|
|
150
|
+
that localized resource/data values are immutable snapshots rather than mutable
|
|
151
|
+
runtime handles.
|
|
152
|
+
|
|
153
|
+
Adapters can check payloads before building catalogs:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { isJsonShapedLocalizedValue } from '@flyingrobots/bijou-i18n';
|
|
157
|
+
|
|
158
|
+
if (!isJsonShapedLocalizedValue(payload)) {
|
|
159
|
+
throw new Error('i18n resource/data payload must be JSON-shaped');
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Valid resource/data payloads are dense, plain data:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
const validResource = {
|
|
167
|
+
label: 'Counter',
|
|
168
|
+
range: { min: 0, max: 10 },
|
|
169
|
+
marks: ['empty', 'half', 'full'],
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Invalid payloads are rejected instead of being silently normalized:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
class CounterResource {
|
|
177
|
+
readonly label = 'Counter';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const sparse = new Array<string>(2);
|
|
181
|
+
sparse[1] = 'full';
|
|
182
|
+
|
|
183
|
+
const accessor = Object.defineProperty({}, 'label', {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
get() {
|
|
186
|
+
return 'Counter';
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
isJsonShapedLocalizedValue(new CounterResource()); // false
|
|
191
|
+
isJsonShapedLocalizedValue(sparse); // false
|
|
192
|
+
isJsonShapedLocalizedValue(accessor); // false
|
|
193
|
+
```
|
|
194
|
+
|
|
16
195
|
## Documentation
|
|
17
196
|
|
|
18
197
|
See the [Bijou repo](https://github.com/flyingrobots/bijou) for the full documentation map, architecture guide, and design system.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { createI18nRuntime, ref, type I18nCatalog, type I18nCatalogEntry, type I18nCatalogKey, type I18nDirection, type I18nEntryKind, type I18nFormatterPort, type I18nReference, type I18nRuntime, type I18nRuntimeOptions, } from './runtime.js';
|
|
1
|
+
export { createI18nRuntimeAsync, createI18nRuntime, ref, type I18nCatalogLoader, type I18nCatalog, type I18nCatalogEntry, type I18nCatalogKey, type I18nDirection, type I18nEntryKind, type I18nFormatterPort, type I18nMissingMessageContext, type I18nMissingMessageFormatter, type I18nMissingReason, type I18nReference, type I18nRuntime, type I18nRuntimeOptions, } from './runtime.js';
|
|
2
|
+
export { createRuntimeLocalizationPort, freezeLocalizedObject, freezeLocalizedValue, isJsonShapedLocalizedValue, type LocalizedObject, type LocalizationFact, type LocalizationFactKind, type LocalizationIssue, type LocalizationIssueCode, type LocalizationPort, type LocalizationRequest, type LocalizationStatus, type RuntimeLocalizationPortSource, } from './localization.js';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,GAAG,EACH,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,GAAG,EACH,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,6BAA6B,GACnC,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { createI18nRuntime, ref, } from './runtime.js';
|
|
1
|
+
export { createI18nRuntimeAsync, createI18nRuntime, ref, } from './runtime.js';
|
|
2
|
+
export { createRuntimeLocalizationPort, freezeLocalizedObject, freezeLocalizedValue, isJsonShapedLocalizedValue, } from './localization.js';
|
|
2
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,GAAG,GAcJ,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,GAU3B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
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<Value = unknown>(request: LocalizationRequest): LocalizedObject<Value>;
|
|
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<Value = unknown>(request: LocalizationRequest): LocalizedObject<Value>;
|
|
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;
|
|
79
|
+
//# sourceMappingURL=localization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../src/localization.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;AAEvE,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;AAED,MAAM,MAAM,qBAAqB,GAC7B,aAAa,GACb,gBAAgB,GAChB,eAAe,GACf,uBAAuB,CAAC;AAE5B,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,oBAAoB,GAC5B,QAAQ,GACR,WAAW,GACX,qBAAq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CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAChF,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;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,6BAA6B,GACrC,gBAAgB,CAwBlB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EACzC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,GAC7B,eAAe,CAAC,KAAK,CAAC,CAWxB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOlE"}
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
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
|
+
return cloneLocalizedValue(value, 'value', new WeakSet());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check whether a value can cross the localization resource/data boundary.
|
|
50
|
+
*
|
|
51
|
+
* This performs the same validation as {@link freezeLocalizedValue} without
|
|
52
|
+
* exposing the frozen clone. Adapter code can use it to reject non-portable
|
|
53
|
+
* payloads before constructing catalogs.
|
|
54
|
+
*/
|
|
55
|
+
export function isJsonShapedLocalizedValue(value) {
|
|
56
|
+
try {
|
|
57
|
+
freezeLocalizedValue(value);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function cloneLocalizedValue(value, path, seen) {
|
|
65
|
+
if (value == null || typeof value !== 'object') {
|
|
66
|
+
if (typeof value === 'bigint' || typeof value === 'symbol' || typeof value === 'function') {
|
|
67
|
+
throw new Error(`Localized value contains unsupported ${typeof value} at ${path}`);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
const objectValue = value;
|
|
72
|
+
if (seen.has(objectValue)) {
|
|
73
|
+
throw new Error(`Localized value contains circular reference at ${path}`);
|
|
74
|
+
}
|
|
75
|
+
seen.add(objectValue);
|
|
76
|
+
try {
|
|
77
|
+
return cloneLocalizedObjectValue(value, path, seen);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
seen.delete(objectValue);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function cloneLocalizedObjectValue(value, path, seen) {
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
validateLocalizedArray(value, path);
|
|
86
|
+
return Object.freeze(value.map((item, index) => cloneLocalizedValue(item, `${path}[${index}]`, seen)));
|
|
87
|
+
}
|
|
88
|
+
const prototype = Object.getPrototypeOf(value);
|
|
89
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
90
|
+
throw new Error(`Localized value contains unsupported ${objectKind(value)} at ${path}`);
|
|
91
|
+
}
|
|
92
|
+
const output = {};
|
|
93
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
94
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
95
|
+
if (typeof key === 'symbol') {
|
|
96
|
+
throw new Error(`Localized value contains unsupported symbol property at ${path}`);
|
|
97
|
+
}
|
|
98
|
+
const descriptor = descriptors[key];
|
|
99
|
+
if (descriptor === undefined) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const propertyPath = `${path}.${key}`;
|
|
103
|
+
if (!descriptor.enumerable) {
|
|
104
|
+
throw new Error(`Localized value contains unsupported non-enumerable property: ${propertyPath}`);
|
|
105
|
+
}
|
|
106
|
+
if (!('value' in descriptor)) {
|
|
107
|
+
throw new Error(`Localized value contains unsupported accessor property: ${propertyPath}`);
|
|
108
|
+
}
|
|
109
|
+
output[key] = cloneLocalizedValue(descriptor.value, propertyPath, seen);
|
|
110
|
+
}
|
|
111
|
+
return Object.freeze(output);
|
|
112
|
+
}
|
|
113
|
+
function validateLocalizedArray(value, path) {
|
|
114
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
115
|
+
let indexedPropertyCount = 0;
|
|
116
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
117
|
+
if (typeof key === 'symbol') {
|
|
118
|
+
throw new Error(`Localized value contains unsupported symbol property at ${path}`);
|
|
119
|
+
}
|
|
120
|
+
if (key === 'length') {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const descriptor = descriptors[key];
|
|
124
|
+
if (descriptor === undefined) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const propertyPath = arrayPropertyPath(path, key);
|
|
128
|
+
if (!descriptor.enumerable) {
|
|
129
|
+
throw new Error(`Localized value contains unsupported non-enumerable property: ${propertyPath}`);
|
|
130
|
+
}
|
|
131
|
+
if (!('value' in descriptor)) {
|
|
132
|
+
throw new Error(`Localized value contains unsupported accessor property: ${propertyPath}`);
|
|
133
|
+
}
|
|
134
|
+
if (!isArrayIndexKey(key)) {
|
|
135
|
+
throw new Error(`Localized value contains unsupported array property: ${propertyPath}`);
|
|
136
|
+
}
|
|
137
|
+
indexedPropertyCount += 1;
|
|
138
|
+
}
|
|
139
|
+
if (indexedPropertyCount !== value.length) {
|
|
140
|
+
throw new Error(`Localized value contains unsupported sparse array at ${path}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function arrayPropertyPath(path, key) {
|
|
144
|
+
return isArrayIndexKey(key) ? `${path}[${key}]` : `${path}.${key}`;
|
|
145
|
+
}
|
|
146
|
+
function isArrayIndexKey(key) {
|
|
147
|
+
if (key === '') {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const index = Number(key);
|
|
151
|
+
return Number.isInteger(index)
|
|
152
|
+
&& index >= 0
|
|
153
|
+
&& index < 2 ** 32 - 1
|
|
154
|
+
&& String(index) === key;
|
|
155
|
+
}
|
|
156
|
+
function objectKind(value) {
|
|
157
|
+
return Object.prototype.toString.call(value).slice(8, -1);
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../src/localization.ts"],"names":[],"mappings":"AAkFA,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,CAAkB,OAA4B;YACnD,OAAO,OAAO,CAAC,QAAQ,CAAQ,OAAO,CAAC,CAAC;QAC1C,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;AAED,MAAM,UAAU,qBAAqB,CACnC,MAA8B;IAE9B,OAAO,MAAM,CAAC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WACV,KAAK,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;WACnB,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;AAC7B,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type LocalizedObject, type LocalizationRequest } from './localization.js';
|
|
1
2
|
export type I18nDirection = 'ltr' | 'rtl' | 'auto';
|
|
2
3
|
export interface I18nCatalogKey {
|
|
3
4
|
readonly namespace: string;
|
|
@@ -24,20 +25,39 @@ export interface I18nFormatterPort {
|
|
|
24
25
|
formatTime(value: Date, locale: string): string;
|
|
25
26
|
formatList(values: readonly string[], locale: string): string;
|
|
26
27
|
}
|
|
28
|
+
export type I18nCatalogLoader = (locale: string) => Promise<readonly I18nCatalog[]>;
|
|
29
|
+
export type I18nMissingReason = 'missing-key' | 'missing-locale';
|
|
30
|
+
export interface I18nMissingMessageContext {
|
|
31
|
+
readonly key: I18nCatalogKey;
|
|
32
|
+
readonly locale: string;
|
|
33
|
+
readonly fallbackLocale: string;
|
|
34
|
+
readonly sourceLocale?: string;
|
|
35
|
+
readonly reason: I18nMissingReason;
|
|
36
|
+
}
|
|
37
|
+
export type I18nMissingMessageFormatter = (context: I18nMissingMessageContext) => string;
|
|
27
38
|
export interface I18nRuntimeOptions {
|
|
28
39
|
readonly locale: string;
|
|
29
40
|
readonly direction: I18nDirection;
|
|
30
41
|
readonly fallbackLocale?: string;
|
|
31
42
|
readonly formatter?: Partial<I18nFormatterPort>;
|
|
43
|
+
readonly fallbackCatalogs?: readonly I18nCatalog[];
|
|
44
|
+
readonly catalogs?: readonly I18nCatalog[];
|
|
45
|
+
readonly loader?: I18nCatalogLoader;
|
|
46
|
+
readonly missingMessage?: I18nMissingMessageFormatter;
|
|
32
47
|
}
|
|
33
48
|
export interface I18nRuntime extends I18nFormatterPort {
|
|
34
49
|
readonly locale: string;
|
|
35
50
|
readonly direction: I18nDirection;
|
|
36
51
|
loadCatalog(catalog: I18nCatalog): void;
|
|
52
|
+
loadCatalogs(catalogs: readonly I18nCatalog[]): void;
|
|
37
53
|
unloadCatalog(namespace: string): void;
|
|
54
|
+
preloadLocale(locale: string): Promise<void>;
|
|
55
|
+
setLocale(locale: string, direction?: I18nDirection): Promise<void>;
|
|
56
|
+
localize<Value = unknown>(request: LocalizationRequest): LocalizedObject<Value>;
|
|
38
57
|
t(key: I18nCatalogKey, values?: Readonly<Record<string, unknown>>): string;
|
|
39
58
|
resource<T = unknown>(key: I18nCatalogKey): T | undefined;
|
|
40
59
|
}
|
|
41
60
|
export declare function ref(key: I18nCatalogKey): I18nReference;
|
|
42
61
|
export declare function createI18nRuntime(options: I18nRuntimeOptions): I18nRuntime;
|
|
62
|
+
export declare function createI18nRuntimeAsync(options: I18nRuntimeOptions): Promise<I18nRuntime>;
|
|
43
63
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,QAAQ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AAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,QAAQ,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;IAC3E,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,CAAC,GAAG,SAAS,CAAC;CAC3D;AA0CD,wBAAgB,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,aAAa,CAEtD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAmZ1E;AAkBD,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAM9F"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { freezeLocalizedObject, freezeLocalizedValue, } from './localization.js';
|
|
1
2
|
const DEFAULT_FORMATTER = {
|
|
2
3
|
formatNumber(value, locale) {
|
|
3
4
|
return new Intl.NumberFormat(locale).format(value);
|
|
@@ -33,19 +34,74 @@ export function ref(key) {
|
|
|
33
34
|
}
|
|
34
35
|
export function createI18nRuntime(options) {
|
|
35
36
|
const entries = new Map();
|
|
36
|
-
const
|
|
37
|
+
const fallbackCatalogs = new Map();
|
|
38
|
+
const manualCatalogs = new Map();
|
|
39
|
+
const loaderCatalogs = new Map();
|
|
40
|
+
const loaderCache = new Map();
|
|
37
41
|
const formatter = { ...DEFAULT_FORMATTER, ...(options.formatter ?? {}) };
|
|
38
42
|
const fallbackLocale = options.fallbackLocale ?? 'en';
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
let currentLocale = options.locale;
|
|
44
|
+
let currentDirection = options.direction;
|
|
45
|
+
function rememberCatalog(target, catalog) {
|
|
46
|
+
target.set(catalog.namespace, catalog);
|
|
47
|
+
}
|
|
48
|
+
function applyCatalogsTo(targetEntries, source) {
|
|
49
|
+
for (const catalog of source.values()) {
|
|
50
|
+
for (const entry of catalog.entries) {
|
|
51
|
+
const key = keyToString(entry.key);
|
|
52
|
+
const existing = targetEntries.get(key);
|
|
53
|
+
targetEntries.set(key, existing === undefined ? entry : mergeCatalogEntry(existing, entry));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function buildCatalogState(stagedLoaderCatalogs = loaderCatalogs) {
|
|
58
|
+
const nextEntries = new Map();
|
|
59
|
+
applyCatalogsTo(nextEntries, fallbackCatalogs);
|
|
60
|
+
applyCatalogsTo(nextEntries, manualCatalogs);
|
|
61
|
+
applyCatalogsTo(nextEntries, stagedLoaderCatalogs);
|
|
62
|
+
return nextEntries;
|
|
63
|
+
}
|
|
64
|
+
function commitCatalogState(nextEntries) {
|
|
65
|
+
entries.clear();
|
|
66
|
+
for (const [key, entry] of nextEntries) {
|
|
67
|
+
entries.set(key, entry);
|
|
43
68
|
}
|
|
44
|
-
return entry;
|
|
45
69
|
}
|
|
46
|
-
function
|
|
70
|
+
function rebuildCatalogState() {
|
|
71
|
+
commitCatalogState(buildCatalogState());
|
|
72
|
+
}
|
|
73
|
+
function localizationIssue(code, key, message) {
|
|
74
|
+
return {
|
|
75
|
+
code,
|
|
76
|
+
key,
|
|
77
|
+
locale: currentLocale,
|
|
78
|
+
fallbackLocale,
|
|
79
|
+
message,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function resolveLocalizedValueResult(entry, seen, options = {}) {
|
|
83
|
+
const localized = entry.values[currentLocale];
|
|
84
|
+
if (localized !== undefined) {
|
|
85
|
+
return resolveCandidateResult(localized, seen, options, 'translated');
|
|
86
|
+
}
|
|
87
|
+
if (options.missingMessage !== undefined
|
|
88
|
+
&& currentLocale !== entry.sourceLocale
|
|
89
|
+
&& currentLocale !== fallbackLocale) {
|
|
90
|
+
return {
|
|
91
|
+
status: 'missing',
|
|
92
|
+
value: options.missingMessage({
|
|
93
|
+
key: entry.key,
|
|
94
|
+
locale: currentLocale,
|
|
95
|
+
fallbackLocale,
|
|
96
|
+
sourceLocale: entry.sourceLocale,
|
|
97
|
+
reason: 'missing-locale',
|
|
98
|
+
}),
|
|
99
|
+
issues: [
|
|
100
|
+
localizationIssue('missing-locale', entry.key, `Missing selected-locale value for ${keyToString(entry.key)}`),
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
47
104
|
const candidates = [
|
|
48
|
-
entry.values[options.locale],
|
|
49
105
|
entry.values[entry.sourceLocale],
|
|
50
106
|
entry.values[fallbackLocale],
|
|
51
107
|
entry.fallbackValue,
|
|
@@ -54,66 +110,242 @@ export function createI18nRuntime(options) {
|
|
|
54
110
|
if (candidate === undefined) {
|
|
55
111
|
continue;
|
|
56
112
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
113
|
+
return resolveCandidateResult(candidate, seen, options, 'fallback');
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
status: 'missing',
|
|
117
|
+
issues: [
|
|
118
|
+
localizationIssue('missing-locale', entry.key, `Missing localized value for ${keyToString(entry.key)}`),
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function resolveLocalizedValue(entry, seen, options = {}) {
|
|
123
|
+
return resolveLocalizedValueResult(entry, seen, options).value;
|
|
124
|
+
}
|
|
125
|
+
function mergeResolutionStatus(candidateStatus, referencedStatus) {
|
|
126
|
+
if (candidateStatus === 'missing' || referencedStatus === 'missing') {
|
|
127
|
+
return 'missing';
|
|
128
|
+
}
|
|
129
|
+
if (candidateStatus === 'fallback' || referencedStatus === 'fallback') {
|
|
130
|
+
return 'fallback';
|
|
131
|
+
}
|
|
132
|
+
return 'translated';
|
|
133
|
+
}
|
|
134
|
+
function resolveCandidateResult(candidate, seen, options = {}, candidateStatus) {
|
|
135
|
+
if (isReference(candidate)) {
|
|
136
|
+
const refKey = keyToString(candidate.$ref);
|
|
137
|
+
if (seen.has(refKey)) {
|
|
138
|
+
throw new Error(`Cyclic i18n reference: ${refKey}`);
|
|
139
|
+
}
|
|
140
|
+
seen.add(refKey);
|
|
141
|
+
const referencedEntry = entries.get(refKey);
|
|
142
|
+
if (referencedEntry === undefined) {
|
|
72
143
|
throw new Error(`Missing i18n reference: ${refKey}`);
|
|
73
144
|
}
|
|
74
|
-
|
|
145
|
+
const resolved = resolveLocalizedValueResult(referencedEntry, seen, options);
|
|
146
|
+
seen.delete(refKey);
|
|
147
|
+
if (resolved.value !== undefined) {
|
|
148
|
+
return {
|
|
149
|
+
status: mergeResolutionStatus(candidateStatus, resolved.status),
|
|
150
|
+
value: resolved.value,
|
|
151
|
+
issues: resolved.issues,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
throw new Error(`Missing i18n reference: ${refKey}`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
status: candidateStatus,
|
|
158
|
+
value: candidate,
|
|
159
|
+
issues: [],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function preloadLocale(locale) {
|
|
163
|
+
if (options.loader === undefined || loaderCache.has(locale)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const catalogs = await options.loader(locale);
|
|
167
|
+
loaderCache.set(locale, catalogs);
|
|
168
|
+
}
|
|
169
|
+
async function loadLocaleCatalogs(locale) {
|
|
170
|
+
if (options.loader === undefined) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
await preloadLocale(locale);
|
|
174
|
+
return loaderCache.get(locale) ?? [];
|
|
175
|
+
}
|
|
176
|
+
function activateLoaderCatalogs(catalogs) {
|
|
177
|
+
const stagedLoaderCatalogs = new Map();
|
|
178
|
+
for (const catalog of catalogs) {
|
|
179
|
+
rememberCatalog(stagedLoaderCatalogs, catalog);
|
|
180
|
+
}
|
|
181
|
+
const nextEntries = buildCatalogState(stagedLoaderCatalogs);
|
|
182
|
+
loaderCatalogs.clear();
|
|
183
|
+
for (const [namespace, catalog] of stagedLoaderCatalogs) {
|
|
184
|
+
loaderCatalogs.set(namespace, catalog);
|
|
185
|
+
}
|
|
186
|
+
commitCatalogState(nextEntries);
|
|
187
|
+
}
|
|
188
|
+
if (options.catalogs !== undefined) {
|
|
189
|
+
for (const catalog of options.catalogs) {
|
|
190
|
+
rememberCatalog(manualCatalogs, catalog);
|
|
191
|
+
}
|
|
192
|
+
rebuildCatalogState();
|
|
193
|
+
}
|
|
194
|
+
if (options.fallbackCatalogs !== undefined) {
|
|
195
|
+
for (const catalog of options.fallbackCatalogs) {
|
|
196
|
+
rememberCatalog(fallbackCatalogs, catalog);
|
|
197
|
+
}
|
|
198
|
+
rebuildCatalogState();
|
|
199
|
+
}
|
|
200
|
+
function localizeRequest(request) {
|
|
201
|
+
const entry = entries.get(keyToString(request.key));
|
|
202
|
+
const kind = request.kind ?? entry?.kind ?? 'message';
|
|
203
|
+
const facts = [
|
|
204
|
+
{ kind: 'locale', key: 'locale', value: currentLocale },
|
|
205
|
+
{ kind: 'direction', key: 'direction', value: currentDirection },
|
|
206
|
+
];
|
|
207
|
+
if (entry === undefined) {
|
|
208
|
+
const issue = localizationIssue('missing-key', request.key, `Missing i18n key: ${keyToString(request.key)}`);
|
|
209
|
+
const value = kind === 'message' && options.missingMessage !== undefined
|
|
210
|
+
? interpolate(options.missingMessage({
|
|
211
|
+
key: request.key,
|
|
212
|
+
locale: currentLocale,
|
|
213
|
+
fallbackLocale,
|
|
214
|
+
reason: 'missing-key',
|
|
215
|
+
}), request.values ?? {})
|
|
216
|
+
: undefined;
|
|
217
|
+
return freezeLocalizedObject({
|
|
218
|
+
key: request.key,
|
|
219
|
+
locale: currentLocale,
|
|
220
|
+
fallbackLocale,
|
|
221
|
+
direction: currentDirection,
|
|
222
|
+
kind,
|
|
223
|
+
status: 'missing',
|
|
224
|
+
value,
|
|
225
|
+
issues: [issue],
|
|
226
|
+
facts: [
|
|
227
|
+
...facts,
|
|
228
|
+
{ kind: 'localization-status', key: 'status', value: 'missing' },
|
|
229
|
+
{ kind: 'entry-kind', key: 'kind', value: kind },
|
|
230
|
+
],
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (request.kind !== undefined && entry.kind !== request.kind) {
|
|
234
|
+
const issue = localizationIssue('kind-mismatch', request.key, `Expected ${request.kind} entry for ${keyToString(request.key)} but found ${entry.kind}`);
|
|
235
|
+
return freezeLocalizedObject({
|
|
236
|
+
key: request.key,
|
|
237
|
+
locale: currentLocale,
|
|
238
|
+
fallbackLocale,
|
|
239
|
+
sourceLocale: entry.sourceLocale,
|
|
240
|
+
direction: currentDirection,
|
|
241
|
+
kind: entry.kind,
|
|
242
|
+
status: 'missing',
|
|
243
|
+
issues: [issue],
|
|
244
|
+
facts: [
|
|
245
|
+
...facts,
|
|
246
|
+
{ kind: 'localization-status', key: 'status', value: 'missing' },
|
|
247
|
+
{ kind: 'entry-kind', key: 'kind', value: entry.kind },
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
const resolved = resolveLocalizedValueResult(entry, new Set(), {
|
|
252
|
+
missingMessage: entry.kind === 'message' ? options.missingMessage : undefined,
|
|
253
|
+
});
|
|
254
|
+
let value = resolved.value;
|
|
255
|
+
const issues = [...resolved.issues];
|
|
256
|
+
if (entry.kind === 'message' && value !== undefined) {
|
|
257
|
+
if (typeof value !== 'string') {
|
|
258
|
+
issues.push(localizationIssue('invalid-message-value', request.key, `Resolved message for ${keyToString(request.key)} was not a string`));
|
|
259
|
+
value = undefined;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
value = interpolate(value, request.values ?? {});
|
|
263
|
+
}
|
|
75
264
|
}
|
|
76
|
-
|
|
265
|
+
const status = issues.some((issue) => issue.code === 'invalid-message-value')
|
|
266
|
+
? 'missing'
|
|
267
|
+
: resolved.status;
|
|
268
|
+
return freezeLocalizedObject({
|
|
269
|
+
key: request.key,
|
|
270
|
+
locale: currentLocale,
|
|
271
|
+
fallbackLocale,
|
|
272
|
+
sourceLocale: entry.sourceLocale,
|
|
273
|
+
direction: currentDirection,
|
|
274
|
+
kind: entry.kind,
|
|
275
|
+
status,
|
|
276
|
+
value,
|
|
277
|
+
issues,
|
|
278
|
+
facts: [
|
|
279
|
+
...facts,
|
|
280
|
+
{ kind: 'localization-status', key: 'status', value: status },
|
|
281
|
+
{ kind: 'entry-kind', key: 'kind', value: entry.kind },
|
|
282
|
+
],
|
|
283
|
+
});
|
|
77
284
|
}
|
|
78
285
|
return {
|
|
79
|
-
locale
|
|
80
|
-
|
|
286
|
+
get locale() {
|
|
287
|
+
return currentLocale;
|
|
288
|
+
},
|
|
289
|
+
get direction() {
|
|
290
|
+
return currentDirection;
|
|
291
|
+
},
|
|
81
292
|
loadCatalog(catalog) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
293
|
+
rememberCatalog(manualCatalogs, catalog);
|
|
294
|
+
rebuildCatalogState();
|
|
295
|
+
},
|
|
296
|
+
loadCatalogs(catalogs) {
|
|
297
|
+
for (const catalog of catalogs) {
|
|
298
|
+
rememberCatalog(manualCatalogs, catalog);
|
|
87
299
|
}
|
|
88
|
-
|
|
300
|
+
rebuildCatalogState();
|
|
89
301
|
},
|
|
90
302
|
unloadCatalog(namespace) {
|
|
91
|
-
|
|
92
|
-
|
|
303
|
+
manualCatalogs.delete(namespace);
|
|
304
|
+
loaderCatalogs.delete(namespace);
|
|
305
|
+
rebuildCatalogState();
|
|
306
|
+
},
|
|
307
|
+
preloadLocale,
|
|
308
|
+
async setLocale(locale, direction) {
|
|
309
|
+
if (options.loader === undefined) {
|
|
310
|
+
currentLocale = locale;
|
|
311
|
+
if (direction !== undefined) {
|
|
312
|
+
currentDirection = direction;
|
|
313
|
+
}
|
|
93
314
|
return;
|
|
94
315
|
}
|
|
95
|
-
|
|
96
|
-
|
|
316
|
+
const catalogs = await loadLocaleCatalogs(locale);
|
|
317
|
+
if (catalogs !== undefined) {
|
|
318
|
+
activateLoaderCatalogs(catalogs);
|
|
97
319
|
}
|
|
98
|
-
|
|
320
|
+
currentLocale = locale;
|
|
321
|
+
if (direction !== undefined) {
|
|
322
|
+
currentDirection = direction;
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
localize(request) {
|
|
326
|
+
return localizeRequest(request);
|
|
99
327
|
},
|
|
100
328
|
t(key, values = {}) {
|
|
101
|
-
const entry =
|
|
102
|
-
if (entry.kind !== 'message') {
|
|
329
|
+
const entry = entries.get(keyToString(key));
|
|
330
|
+
if (entry !== undefined && entry.kind !== 'message') {
|
|
103
331
|
throw new Error(`Expected message entry for ${keyToString(key)} but found ${entry.kind}`);
|
|
104
332
|
}
|
|
105
|
-
const resolved =
|
|
106
|
-
if (
|
|
333
|
+
const resolved = localizeRequest({ key, kind: 'message', values });
|
|
334
|
+
if (resolved.value === undefined) {
|
|
335
|
+
throw new Error(`Missing i18n key: ${keyToString(key)}`);
|
|
336
|
+
}
|
|
337
|
+
if (typeof resolved.value !== 'string') {
|
|
107
338
|
throw new Error(`Resolved message for ${keyToString(key)} was not a string`);
|
|
108
339
|
}
|
|
109
|
-
return
|
|
340
|
+
return resolved.value;
|
|
110
341
|
},
|
|
111
342
|
resource(key) {
|
|
112
343
|
const entry = entries.get(keyToString(key));
|
|
113
344
|
if (entry === undefined) {
|
|
114
345
|
return undefined;
|
|
115
346
|
}
|
|
116
|
-
|
|
347
|
+
const resolved = resolveLocalizedValue(entry, new Set());
|
|
348
|
+
return resolved === undefined ? undefined : freezeLocalizedValue(resolved);
|
|
117
349
|
},
|
|
118
350
|
formatNumber(value, locale) {
|
|
119
351
|
return formatter.formatNumber(value, locale);
|
|
@@ -129,4 +361,26 @@ export function createI18nRuntime(options) {
|
|
|
129
361
|
},
|
|
130
362
|
};
|
|
131
363
|
}
|
|
364
|
+
function mergeCatalogEntry(left, right) {
|
|
365
|
+
if (left.kind !== right.kind || left.sourceLocale !== right.sourceLocale) {
|
|
366
|
+
throw new Error(`Conflicting i18n catalog entry metadata for ${keyToString(left.key)}`);
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
key: left.key,
|
|
370
|
+
kind: left.kind,
|
|
371
|
+
sourceLocale: left.sourceLocale,
|
|
372
|
+
values: {
|
|
373
|
+
...left.values,
|
|
374
|
+
...right.values,
|
|
375
|
+
},
|
|
376
|
+
fallbackValue: right.fallbackValue ?? left.fallbackValue,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
export async function createI18nRuntimeAsync(options) {
|
|
380
|
+
const runtime = createI18nRuntime(options);
|
|
381
|
+
if (options.loader !== undefined) {
|
|
382
|
+
await runtime.setLocale(options.locale, options.direction);
|
|
383
|
+
}
|
|
384
|
+
return runtime;
|
|
385
|
+
}
|
|
132
386
|
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAiDA,MAAM,iBAAiB,GAAsB;IAC3C,YAAY,CAAC,KAAK,EAAE,MAAM;QACxB,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IACD,UAAU,CAAC,KAAK,EAAE,MAAM;QACtB,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,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AAC,YAAY,KAAK,KAAK,CAAC,YAAY,EAAE,CAAC;QACzE,MAAM,IAAI,KAAK,CAAC,+CAA+C,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,MAAM,EAAE;YACN,GAAG,IAAI,CAAC,MAAM;YACd,GAAG,KAAK,CAAC,MAAM;SAChB;QACD,aAAa,EAAE,KAAK,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa;KACzD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,OAA2B;IACtE,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyingrobots/bijou-i18n",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "In-memory localization runtime for Bijou — catalogs, locale direction, and runtime-safe lookups.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^22.0.0",
|
|
28
28
|
"typescript": "^5.9.3",
|
|
29
|
-
"vitest": "^4.
|
|
29
|
+
"vitest": "^4.1.8"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
32
32
|
"i18n",
|