@digitaldefiance/i18n-lib 1.1.0 → 1.1.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/README.md +37 -0
- package/dist/core-i18n.d.ts +1 -290
- package/dist/core-i18n.js +3 -2
- 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
|
|
@@ -859,6 +890,12 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
|
|
|
859
890
|
|
|
860
891
|
## ChangeLog
|
|
861
892
|
|
|
893
|
+
### Version 1.1.1
|
|
894
|
+
|
|
895
|
+
- Sat Oct 11 2025 17:47:00 GMT-0700 (Pacific Daylight Time)
|
|
896
|
+
- Improved type checking for completeness of component translations during registration
|
|
897
|
+
- Updated README/Migration guide for clarity.
|
|
898
|
+
|
|
862
899
|
### Version 1.1.0
|
|
863
900
|
|
|
864
901
|
- Sat Oct 11 2025 16:49:00 GMT-0700 (Pacific Daylight Time)
|
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
|
|
@@ -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
|
+
}
|