@digitaldefiance/i18n-lib 1.1.0 → 1.1.2
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 +88 -0
- package/dist/component-registry.d.ts +4 -0
- package/dist/component-registry.js +7 -0
- package/dist/core-i18n.d.ts +1 -290
- package/dist/core-i18n.js +3 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +10 -0
- package/dist/plugin-i18n-engine.d.ts +21 -0
- package/dist/plugin-i18n-engine.js +49 -0
- package/dist/strict-types.d.ts +18 -0
- package/dist/strict-types.js +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -231,6 +231,37 @@ const userNotFound = getUserTranslation(
|
|
|
231
231
|
|
|
232
232
|
### Advanced Plugin Usage
|
|
233
233
|
|
|
234
|
+
#### Compile-Time Completeness Enforcement (Strict Mode)
|
|
235
|
+
|
|
236
|
+
By default the plugin engine performs runtime validation and provides fallbacks. If you want **compile-time** enforcement that every language mapping contains every string key, use the helper in `strict-types`:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { createCompleteComponentStrings } from '@digitaldefiance/i18n-lib';
|
|
240
|
+
|
|
241
|
+
enum MyStrings {
|
|
242
|
+
Welcome = 'welcome',
|
|
243
|
+
Farewell = 'farewell'
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
type AppLang = 'en' | 'fr';
|
|
247
|
+
|
|
248
|
+
// This will only compile if BOTH languages contain BOTH keys.
|
|
249
|
+
const myStrictStrings = createCompleteComponentStrings<MyStrings, AppLang>({
|
|
250
|
+
en: {
|
|
251
|
+
[MyStrings.Welcome]: 'Welcome',
|
|
252
|
+
[MyStrings.Farewell]: 'Goodbye'
|
|
253
|
+
},
|
|
254
|
+
fr: {
|
|
255
|
+
[MyStrings.Welcome]: 'Bienvenue',
|
|
256
|
+
[MyStrings.Farewell]: 'Au revoir'
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// If any key is missing, TypeScript reports an error before runtime.
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
The core library itself uses this helper for the core component (`createCoreComponentStrings`) to guarantee internal completeness. For partial / iterative authoring you can still start with normal objects and later switch to the strict helper when translations stabilize.
|
|
264
|
+
|
|
234
265
|
#### Adding New Languages
|
|
235
266
|
|
|
236
267
|
```typescript
|
|
@@ -690,6 +721,52 @@ yarn test enum-registry.spec.ts
|
|
|
690
721
|
yarn test i18n-engine.spec.ts
|
|
691
722
|
```
|
|
692
723
|
|
|
724
|
+
### Test Cleanup and Instance Management
|
|
725
|
+
|
|
726
|
+
For proper test isolation when using the plugin-based architecture, use the cleanup utilities:
|
|
727
|
+
|
|
728
|
+
```typescript
|
|
729
|
+
import { PluginI18nEngine, resetAllI18nEngines } from '@digitaldefiance/i18n-lib';
|
|
730
|
+
|
|
731
|
+
describe('My tests', () => {
|
|
732
|
+
beforeEach(() => {
|
|
733
|
+
// Clean up any existing instances before each test
|
|
734
|
+
PluginI18nEngine.clearAllInstances();
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
afterEach(() => {
|
|
738
|
+
// Or use the convenience function
|
|
739
|
+
resetAllI18nEngines();
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
// Or use specific cleanup methods
|
|
743
|
+
it('should manage instances', () => {
|
|
744
|
+
const engine1 = PluginI18nEngine.createInstance('app1', [englishLang]);
|
|
745
|
+
const engine2 = PluginI18nEngine.createInstance('app2', [frenchLang]);
|
|
746
|
+
|
|
747
|
+
// Check if instances exist
|
|
748
|
+
expect(PluginI18nEngine.hasInstance('app1')).toBe(true);
|
|
749
|
+
expect(PluginI18nEngine.hasInstance('app2')).toBe(true);
|
|
750
|
+
|
|
751
|
+
// Remove specific instance
|
|
752
|
+
PluginI18nEngine.removeInstance('app1');
|
|
753
|
+
expect(PluginI18nEngine.hasInstance('app1')).toBe(false);
|
|
754
|
+
|
|
755
|
+
// Clear all instances and component registrations
|
|
756
|
+
PluginI18nEngine.resetAll();
|
|
757
|
+
expect(PluginI18nEngine.hasInstance('app2')).toBe(false);
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
#### Available Cleanup Methods
|
|
763
|
+
|
|
764
|
+
- `PluginI18nEngine.clearAllInstances()` - Remove all engine instances
|
|
765
|
+
- `PluginI18nEngine.removeInstance(key?)` - Remove specific instance by key
|
|
766
|
+
- `PluginI18nEngine.hasInstance(key?)` - Check if instance exists
|
|
767
|
+
- `PluginI18nEngine.resetAll()` - Clear instances and component registrations
|
|
768
|
+
- `resetAllI18nEngines()` - Convenience function that calls `resetAll()`
|
|
769
|
+
|
|
693
770
|
## Extensible Configuration
|
|
694
771
|
|
|
695
772
|
The library supports layered extension across multiple libraries using TypeScript module augmentation:
|
|
@@ -859,6 +936,17 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
|
|
|
859
936
|
|
|
860
937
|
## ChangeLog
|
|
861
938
|
|
|
939
|
+
### Version 1.1.2
|
|
940
|
+
|
|
941
|
+
- Sat Oct 11 2025 19:25:00 GMT-0700 (Pacific Daylight Time)
|
|
942
|
+
- Added cleanup mechanisms for other modules to deregister, etc.
|
|
943
|
+
|
|
944
|
+
### Version 1.1.1
|
|
945
|
+
|
|
946
|
+
- Sat Oct 11 2025 17:47:00 GMT-0700 (Pacific Daylight Time)
|
|
947
|
+
- Improved type checking for completeness of component translations during registration
|
|
948
|
+
- Updated README/Migration guide for clarity.
|
|
949
|
+
|
|
862
950
|
### Version 1.1.0
|
|
863
951
|
|
|
864
952
|
- Sat Oct 11 2025 16:49:00 GMT-0700 (Pacific Daylight Time)
|
|
@@ -234,5 +234,12 @@ class ComponentRegistry {
|
|
|
234
234
|
}
|
|
235
235
|
return result;
|
|
236
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Clear all components and their strings (useful for testing)
|
|
239
|
+
*/
|
|
240
|
+
clearAllComponents() {
|
|
241
|
+
this.components.clear();
|
|
242
|
+
this.componentStrings.clear();
|
|
243
|
+
}
|
|
237
244
|
}
|
|
238
245
|
exports.ComponentRegistry = ComponentRegistry;
|
package/dist/core-i18n.d.ts
CHANGED
|
@@ -18,296 +18,7 @@ export declare const CoreComponentDefinition: ComponentDefinition<CoreStringKey>
|
|
|
18
18
|
/**
|
|
19
19
|
* Core component strings for all default languages
|
|
20
20
|
*/
|
|
21
|
-
export declare function createCoreComponentStrings():
|
|
22
|
-
"en-US": {
|
|
23
|
-
common_yes: string;
|
|
24
|
-
common_no: string;
|
|
25
|
-
common_cancel: string;
|
|
26
|
-
common_ok: string;
|
|
27
|
-
common_save: string;
|
|
28
|
-
common_delete: string;
|
|
29
|
-
common_edit: string;
|
|
30
|
-
common_create: string;
|
|
31
|
-
common_update: string;
|
|
32
|
-
common_loading: string;
|
|
33
|
-
common_error: string;
|
|
34
|
-
common_success: string;
|
|
35
|
-
common_warning: string;
|
|
36
|
-
common_info: string;
|
|
37
|
-
error_invalidInput: string;
|
|
38
|
-
error_networkError: string;
|
|
39
|
-
error_notFound: string;
|
|
40
|
-
error_accessDenied: string;
|
|
41
|
-
error_internalServer: string;
|
|
42
|
-
error_validationFailed: string;
|
|
43
|
-
error_requiredField: string;
|
|
44
|
-
error_componentNotFoundTemplate: string;
|
|
45
|
-
error_languageNotFoundTemplate: string;
|
|
46
|
-
error_stringKeyNotFoundTemplate: string;
|
|
47
|
-
error_incompleteRegistrationTemplate: string;
|
|
48
|
-
error_duplicateComponentTemplate: string;
|
|
49
|
-
error_duplicateLanguageTemplate: string;
|
|
50
|
-
error_validationFailedTemplate: string;
|
|
51
|
-
system_welcome: string;
|
|
52
|
-
system_goodbye: string;
|
|
53
|
-
system_pleaseWait: string;
|
|
54
|
-
system_processingRequest: string;
|
|
55
|
-
system_operationComplete: string;
|
|
56
|
-
system_noDataAvailable: string;
|
|
57
|
-
};
|
|
58
|
-
"en-UK": {
|
|
59
|
-
common_yes: string;
|
|
60
|
-
common_no: string;
|
|
61
|
-
common_cancel: string;
|
|
62
|
-
common_ok: string;
|
|
63
|
-
common_save: string;
|
|
64
|
-
common_delete: string;
|
|
65
|
-
common_edit: string;
|
|
66
|
-
common_create: string;
|
|
67
|
-
common_update: string;
|
|
68
|
-
common_loading: string;
|
|
69
|
-
common_error: string;
|
|
70
|
-
common_success: string;
|
|
71
|
-
common_warning: string;
|
|
72
|
-
common_info: string;
|
|
73
|
-
error_invalidInput: string;
|
|
74
|
-
error_networkError: string;
|
|
75
|
-
error_notFound: string;
|
|
76
|
-
error_accessDenied: string;
|
|
77
|
-
error_internalServer: string;
|
|
78
|
-
error_validationFailed: string;
|
|
79
|
-
error_requiredField: string;
|
|
80
|
-
error_componentNotFoundTemplate: string;
|
|
81
|
-
error_languageNotFoundTemplate: string;
|
|
82
|
-
error_stringKeyNotFoundTemplate: string;
|
|
83
|
-
error_incompleteRegistrationTemplate: string;
|
|
84
|
-
error_duplicateComponentTemplate: string;
|
|
85
|
-
error_duplicateLanguageTemplate: string;
|
|
86
|
-
error_validationFailedTemplate: string;
|
|
87
|
-
system_welcome: string;
|
|
88
|
-
system_goodbye: string;
|
|
89
|
-
system_pleaseWait: string;
|
|
90
|
-
system_processingRequest: string;
|
|
91
|
-
system_operationComplete: string;
|
|
92
|
-
system_noDataAvailable: string;
|
|
93
|
-
};
|
|
94
|
-
fr: {
|
|
95
|
-
common_yes: string;
|
|
96
|
-
common_no: string;
|
|
97
|
-
common_cancel: string;
|
|
98
|
-
common_ok: string;
|
|
99
|
-
common_save: string;
|
|
100
|
-
common_delete: string;
|
|
101
|
-
common_edit: string;
|
|
102
|
-
common_create: string;
|
|
103
|
-
common_update: string;
|
|
104
|
-
common_loading: string;
|
|
105
|
-
common_error: string;
|
|
106
|
-
common_success: string;
|
|
107
|
-
common_warning: string;
|
|
108
|
-
common_info: string;
|
|
109
|
-
error_invalidInput: string;
|
|
110
|
-
error_networkError: string;
|
|
111
|
-
error_notFound: string;
|
|
112
|
-
error_accessDenied: string;
|
|
113
|
-
error_internalServer: string;
|
|
114
|
-
error_validationFailed: string;
|
|
115
|
-
error_requiredField: string;
|
|
116
|
-
error_componentNotFoundTemplate: string;
|
|
117
|
-
error_languageNotFoundTemplate: string;
|
|
118
|
-
error_stringKeyNotFoundTemplate: string;
|
|
119
|
-
error_incompleteRegistrationTemplate: string;
|
|
120
|
-
error_duplicateComponentTemplate: string;
|
|
121
|
-
error_duplicateLanguageTemplate: string;
|
|
122
|
-
error_validationFailedTemplate: string;
|
|
123
|
-
system_welcome: string;
|
|
124
|
-
system_goodbye: string;
|
|
125
|
-
system_pleaseWait: string;
|
|
126
|
-
system_processingRequest: string;
|
|
127
|
-
system_operationComplete: string;
|
|
128
|
-
system_noDataAvailable: string;
|
|
129
|
-
};
|
|
130
|
-
es: {
|
|
131
|
-
common_yes: string;
|
|
132
|
-
common_no: string;
|
|
133
|
-
common_cancel: string;
|
|
134
|
-
common_ok: string;
|
|
135
|
-
common_save: string;
|
|
136
|
-
common_delete: string;
|
|
137
|
-
common_edit: string;
|
|
138
|
-
common_create: string;
|
|
139
|
-
common_update: string;
|
|
140
|
-
common_loading: string;
|
|
141
|
-
common_error: string;
|
|
142
|
-
common_success: string;
|
|
143
|
-
common_warning: string;
|
|
144
|
-
common_info: string;
|
|
145
|
-
error_invalidInput: string;
|
|
146
|
-
error_networkError: string;
|
|
147
|
-
error_notFound: string;
|
|
148
|
-
error_accessDenied: string;
|
|
149
|
-
error_internalServer: string;
|
|
150
|
-
error_validationFailed: string;
|
|
151
|
-
error_requiredField: string;
|
|
152
|
-
error_componentNotFoundTemplate: string;
|
|
153
|
-
error_languageNotFoundTemplate: string;
|
|
154
|
-
error_stringKeyNotFoundTemplate: string;
|
|
155
|
-
error_incompleteRegistrationTemplate: string;
|
|
156
|
-
error_duplicateComponentTemplate: string;
|
|
157
|
-
error_duplicateLanguageTemplate: string;
|
|
158
|
-
error_validationFailedTemplate: string;
|
|
159
|
-
system_welcome: string;
|
|
160
|
-
system_goodbye: string;
|
|
161
|
-
system_pleaseWait: string;
|
|
162
|
-
system_processingRequest: string;
|
|
163
|
-
system_operationComplete: string;
|
|
164
|
-
system_noDataAvailable: string;
|
|
165
|
-
};
|
|
166
|
-
de: {
|
|
167
|
-
common_yes: string;
|
|
168
|
-
common_no: string;
|
|
169
|
-
common_cancel: string;
|
|
170
|
-
common_ok: string;
|
|
171
|
-
common_save: string;
|
|
172
|
-
common_delete: string;
|
|
173
|
-
common_edit: string;
|
|
174
|
-
common_create: string;
|
|
175
|
-
common_update: string;
|
|
176
|
-
common_loading: string;
|
|
177
|
-
common_error: string;
|
|
178
|
-
common_success: string;
|
|
179
|
-
common_warning: string;
|
|
180
|
-
common_info: string;
|
|
181
|
-
error_invalidInput: string;
|
|
182
|
-
error_networkError: string;
|
|
183
|
-
error_notFound: string;
|
|
184
|
-
error_accessDenied: string;
|
|
185
|
-
error_internalServer: string;
|
|
186
|
-
error_validationFailed: string;
|
|
187
|
-
error_requiredField: string;
|
|
188
|
-
error_componentNotFoundTemplate: string;
|
|
189
|
-
error_languageNotFoundTemplate: string;
|
|
190
|
-
error_stringKeyNotFoundTemplate: string;
|
|
191
|
-
error_incompleteRegistrationTemplate: string;
|
|
192
|
-
error_duplicateComponentTemplate: string;
|
|
193
|
-
error_duplicateLanguageTemplate: string;
|
|
194
|
-
error_validationFailedTemplate: string;
|
|
195
|
-
system_welcome: string;
|
|
196
|
-
system_goodbye: string;
|
|
197
|
-
system_pleaseWait: string;
|
|
198
|
-
system_processingRequest: string;
|
|
199
|
-
system_operationComplete: string;
|
|
200
|
-
system_noDataAvailable: string;
|
|
201
|
-
};
|
|
202
|
-
"zh-CN": {
|
|
203
|
-
common_yes: string;
|
|
204
|
-
common_no: string;
|
|
205
|
-
common_cancel: string;
|
|
206
|
-
common_ok: string;
|
|
207
|
-
common_save: string;
|
|
208
|
-
common_delete: string;
|
|
209
|
-
common_edit: string;
|
|
210
|
-
common_create: string;
|
|
211
|
-
common_update: string;
|
|
212
|
-
common_loading: string;
|
|
213
|
-
common_error: string;
|
|
214
|
-
common_success: string;
|
|
215
|
-
common_warning: string;
|
|
216
|
-
common_info: string;
|
|
217
|
-
error_invalidInput: string;
|
|
218
|
-
error_networkError: string;
|
|
219
|
-
error_notFound: string;
|
|
220
|
-
error_accessDenied: string;
|
|
221
|
-
error_internalServer: string;
|
|
222
|
-
error_validationFailed: string;
|
|
223
|
-
error_requiredField: string;
|
|
224
|
-
error_componentNotFoundTemplate: string;
|
|
225
|
-
error_languageNotFoundTemplate: string;
|
|
226
|
-
error_stringKeyNotFoundTemplate: string;
|
|
227
|
-
error_incompleteRegistrationTemplate: string;
|
|
228
|
-
error_duplicateComponentTemplate: string;
|
|
229
|
-
error_duplicateLanguageTemplate: string;
|
|
230
|
-
error_validationFailedTemplate: string;
|
|
231
|
-
system_welcome: string;
|
|
232
|
-
system_goodbye: string;
|
|
233
|
-
system_pleaseWait: string;
|
|
234
|
-
system_processingRequest: string;
|
|
235
|
-
system_operationComplete: string;
|
|
236
|
-
system_noDataAvailable: string;
|
|
237
|
-
};
|
|
238
|
-
ja: {
|
|
239
|
-
common_yes: string;
|
|
240
|
-
common_no: string;
|
|
241
|
-
common_cancel: string;
|
|
242
|
-
common_ok: string;
|
|
243
|
-
common_save: string;
|
|
244
|
-
common_delete: string;
|
|
245
|
-
common_edit: string;
|
|
246
|
-
common_create: string;
|
|
247
|
-
common_update: string;
|
|
248
|
-
common_loading: string;
|
|
249
|
-
common_error: string;
|
|
250
|
-
common_success: string;
|
|
251
|
-
common_warning: string;
|
|
252
|
-
common_info: string;
|
|
253
|
-
error_invalidInput: string;
|
|
254
|
-
error_networkError: string;
|
|
255
|
-
error_notFound: string;
|
|
256
|
-
error_accessDenied: string;
|
|
257
|
-
error_internalServer: string;
|
|
258
|
-
error_validationFailed: string;
|
|
259
|
-
error_requiredField: string;
|
|
260
|
-
error_componentNotFoundTemplate: string;
|
|
261
|
-
error_languageNotFoundTemplate: string;
|
|
262
|
-
error_stringKeyNotFoundTemplate: string;
|
|
263
|
-
error_incompleteRegistrationTemplate: string;
|
|
264
|
-
error_duplicateComponentTemplate: string;
|
|
265
|
-
error_duplicateLanguageTemplate: string;
|
|
266
|
-
error_validationFailedTemplate: string;
|
|
267
|
-
system_welcome: string;
|
|
268
|
-
system_goodbye: string;
|
|
269
|
-
system_pleaseWait: string;
|
|
270
|
-
system_processingRequest: string;
|
|
271
|
-
system_operationComplete: string;
|
|
272
|
-
system_noDataAvailable: string;
|
|
273
|
-
};
|
|
274
|
-
uk: {
|
|
275
|
-
common_yes: string;
|
|
276
|
-
common_no: string;
|
|
277
|
-
common_cancel: string;
|
|
278
|
-
common_ok: string;
|
|
279
|
-
common_save: string;
|
|
280
|
-
common_delete: string;
|
|
281
|
-
common_edit: string;
|
|
282
|
-
common_create: string;
|
|
283
|
-
common_update: string;
|
|
284
|
-
common_loading: string;
|
|
285
|
-
common_error: string;
|
|
286
|
-
common_success: string;
|
|
287
|
-
common_warning: string;
|
|
288
|
-
common_info: string;
|
|
289
|
-
error_invalidInput: string;
|
|
290
|
-
error_networkError: string;
|
|
291
|
-
error_notFound: string;
|
|
292
|
-
error_accessDenied: string;
|
|
293
|
-
error_internalServer: string;
|
|
294
|
-
error_validationFailed: string;
|
|
295
|
-
error_requiredField: string;
|
|
296
|
-
error_componentNotFoundTemplate: string;
|
|
297
|
-
error_languageNotFoundTemplate: string;
|
|
298
|
-
error_stringKeyNotFoundTemplate: string;
|
|
299
|
-
error_incompleteRegistrationTemplate: string;
|
|
300
|
-
error_duplicateComponentTemplate: string;
|
|
301
|
-
error_duplicateLanguageTemplate: string;
|
|
302
|
-
error_validationFailedTemplate: string;
|
|
303
|
-
system_welcome: string;
|
|
304
|
-
system_goodbye: string;
|
|
305
|
-
system_pleaseWait: string;
|
|
306
|
-
system_processingRequest: string;
|
|
307
|
-
system_operationComplete: string;
|
|
308
|
-
system_noDataAvailable: string;
|
|
309
|
-
};
|
|
310
|
-
};
|
|
21
|
+
export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey, CoreLanguage>;
|
|
311
22
|
/**
|
|
312
23
|
* Create core component registration
|
|
313
24
|
*/
|
package/dist/core-i18n.js
CHANGED
|
@@ -14,6 +14,7 @@ const core_language_1 = require("./core-language");
|
|
|
14
14
|
const core_string_key_1 = require("./core-string-key");
|
|
15
15
|
const language_registry_1 = require("./language-registry");
|
|
16
16
|
const plugin_i18n_engine_1 = require("./plugin-i18n-engine");
|
|
17
|
+
const strict_types_1 = require("./strict-types");
|
|
17
18
|
/**
|
|
18
19
|
* Create default language definitions
|
|
19
20
|
*/
|
|
@@ -74,7 +75,7 @@ exports.CoreComponentDefinition = {
|
|
|
74
75
|
* Core component strings for all default languages
|
|
75
76
|
*/
|
|
76
77
|
function createCoreComponentStrings() {
|
|
77
|
-
return {
|
|
78
|
+
return (0, strict_types_1.createCompleteComponentStrings)({
|
|
78
79
|
[core_language_1.CoreLanguage.EnglishUS]: {
|
|
79
80
|
// Common/General
|
|
80
81
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Yes',
|
|
@@ -395,7 +396,7 @@ function createCoreComponentStrings() {
|
|
|
395
396
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Операція успішно завершена',
|
|
396
397
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'Дані недоступні',
|
|
397
398
|
},
|
|
398
|
-
};
|
|
399
|
+
});
|
|
399
400
|
}
|
|
400
401
|
/**
|
|
401
402
|
* Create core component registration
|
package/dist/index.d.ts
CHANGED
|
@@ -33,3 +33,8 @@ export * from './translation-response';
|
|
|
33
33
|
export { createCoreI18nEngine as createCoreI18n } from './core-i18n';
|
|
34
34
|
export { I18nEngine as I18n } from './i18n-engine';
|
|
35
35
|
export { PluginI18nEngine as PluginI18n } from './plugin-i18n-engine';
|
|
36
|
+
/**
|
|
37
|
+
* Reset all I18n engines and clear component registrations
|
|
38
|
+
* Useful for test cleanup
|
|
39
|
+
*/
|
|
40
|
+
export declare function resetAllI18nEngines(): void;
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.PluginI18n = exports.I18n = exports.createCoreI18n = void 0;
|
|
18
|
+
exports.resetAllI18nEngines = resetAllI18nEngines;
|
|
18
19
|
// Legacy exports (for backwards compatibility)
|
|
19
20
|
__exportStar(require("./active-context"), exports);
|
|
20
21
|
__exportStar(require("./component-definition"), exports);
|
|
@@ -55,3 +56,12 @@ var i18n_engine_1 = require("./i18n-engine");
|
|
|
55
56
|
Object.defineProperty(exports, "I18n", { enumerable: true, get: function () { return i18n_engine_1.I18nEngine; } });
|
|
56
57
|
var plugin_i18n_engine_1 = require("./plugin-i18n-engine");
|
|
57
58
|
Object.defineProperty(exports, "PluginI18n", { enumerable: true, get: function () { return plugin_i18n_engine_1.PluginI18nEngine; } });
|
|
59
|
+
// Testing utilities
|
|
60
|
+
const plugin_i18n_engine_2 = require("./plugin-i18n-engine");
|
|
61
|
+
/**
|
|
62
|
+
* Reset all I18n engines and clear component registrations
|
|
63
|
+
* Useful for test cleanup
|
|
64
|
+
*/
|
|
65
|
+
function resetAllI18nEngines() {
|
|
66
|
+
plugin_i18n_engine_2.PluginI18nEngine.resetAll();
|
|
67
|
+
}
|
|
@@ -123,4 +123,25 @@ export declare class PluginI18nEngine<TLanguages extends string> {
|
|
|
123
123
|
errors: string[];
|
|
124
124
|
warnings: string[];
|
|
125
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* Clear all component registrations for this instance (useful for testing)
|
|
128
|
+
*/
|
|
129
|
+
clearAllComponents(): void;
|
|
130
|
+
/**
|
|
131
|
+
* Clear all named instances (useful for testing)
|
|
132
|
+
*/
|
|
133
|
+
static clearAllInstances(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Remove a specific named instance
|
|
136
|
+
*/
|
|
137
|
+
static removeInstance(key?: string): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Check if an instance exists
|
|
140
|
+
*/
|
|
141
|
+
static hasInstance(key?: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Reset all plugin engines and clear component registrations
|
|
144
|
+
* Useful for test cleanup
|
|
145
|
+
*/
|
|
146
|
+
static resetAll(): void;
|
|
126
147
|
}
|
|
@@ -49,6 +49,11 @@ class PluginI18nEngine {
|
|
|
49
49
|
timezone: this.config.timezone,
|
|
50
50
|
adminTimezone: this.config.adminTimezone,
|
|
51
51
|
};
|
|
52
|
+
// Auto-register as default instance if none exists
|
|
53
|
+
if (!PluginI18nEngine._defaultKey) {
|
|
54
|
+
PluginI18nEngine._instances.set(PluginI18nEngine.DefaultInstanceKey, this);
|
|
55
|
+
PluginI18nEngine._defaultKey = PluginI18nEngine.DefaultInstanceKey;
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
/**
|
|
54
59
|
* Create a new instance with a specific key
|
|
@@ -256,6 +261,50 @@ class PluginI18nEngine {
|
|
|
256
261
|
}
|
|
257
262
|
return { isValid, errors, warnings };
|
|
258
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Clear all component registrations for this instance (useful for testing)
|
|
266
|
+
*/
|
|
267
|
+
clearAllComponents() {
|
|
268
|
+
this.componentRegistry.clearAllComponents();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Clear all named instances (useful for testing)
|
|
272
|
+
*/
|
|
273
|
+
static clearAllInstances() {
|
|
274
|
+
PluginI18nEngine._instances.clear();
|
|
275
|
+
PluginI18nEngine._defaultKey = null;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Remove a specific named instance
|
|
279
|
+
*/
|
|
280
|
+
static removeInstance(key) {
|
|
281
|
+
const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
|
|
282
|
+
const removed = PluginI18nEngine._instances.delete(instanceKey);
|
|
283
|
+
// If we removed the default instance, clear the default key
|
|
284
|
+
if (removed && PluginI18nEngine._defaultKey === instanceKey) {
|
|
285
|
+
PluginI18nEngine._defaultKey = null;
|
|
286
|
+
}
|
|
287
|
+
return removed;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Check if an instance exists
|
|
291
|
+
*/
|
|
292
|
+
static hasInstance(key) {
|
|
293
|
+
const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
|
|
294
|
+
return PluginI18nEngine._instances.has(instanceKey);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Reset all plugin engines and clear component registrations
|
|
298
|
+
* Useful for test cleanup
|
|
299
|
+
*/
|
|
300
|
+
static resetAll() {
|
|
301
|
+
for (const [key, engine] of PluginI18nEngine._instances) {
|
|
302
|
+
// Clear component registrations for each engine
|
|
303
|
+
engine.clearAllComponents();
|
|
304
|
+
}
|
|
305
|
+
PluginI18nEngine._instances.clear();
|
|
306
|
+
PluginI18nEngine._defaultKey = null;
|
|
307
|
+
}
|
|
259
308
|
}
|
|
260
309
|
exports.PluginI18nEngine = PluginI18nEngine;
|
|
261
310
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enforces that for each language L, all string keys K are present.
|
|
3
|
+
*/
|
|
4
|
+
export type CompleteLanguageStrings<TStringKey extends string> = {
|
|
5
|
+
[K in TStringKey]: string;
|
|
6
|
+
};
|
|
7
|
+
export type CompleteComponentLanguageStrings<TStringKey extends string, TLanguages extends string> = {
|
|
8
|
+
[L in TLanguages]: CompleteLanguageStrings<TStringKey>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Helper to assert at compile-time that an object is a complete component language map.
|
|
12
|
+
* Returns the object unchanged at runtime.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createCompleteComponentStrings<TStringKey extends string, TLanguages extends string>(obj: CompleteComponentLanguageStrings<TStringKey, TLanguages>): CompleteComponentLanguageStrings<TStringKey, TLanguages>;
|
|
15
|
+
/**
|
|
16
|
+
* Utility to extract missing keys at compile time (identity, purely for readability)
|
|
17
|
+
*/
|
|
18
|
+
export declare function defineLanguageStrings<TStringKey extends string>(strings: CompleteLanguageStrings<TStringKey>): CompleteLanguageStrings<TStringKey>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCompleteComponentStrings = createCompleteComponentStrings;
|
|
4
|
+
exports.defineLanguageStrings = defineLanguageStrings;
|
|
5
|
+
/**
|
|
6
|
+
* Helper to assert at compile-time that an object is a complete component language map.
|
|
7
|
+
* Returns the object unchanged at runtime.
|
|
8
|
+
*/
|
|
9
|
+
function createCompleteComponentStrings(obj) {
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Utility to extract missing keys at compile time (identity, purely for readability)
|
|
14
|
+
*/
|
|
15
|
+
function defineLanguageStrings(strings) {
|
|
16
|
+
return strings;
|
|
17
|
+
}
|