@digitaldefiance/i18n-lib 1.1.10 → 1.2.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 +127 -49
- package/dist/core-i18n.d.ts +8 -7
- package/dist/core-i18n.js +17 -17
- package/dist/default-config.d.ts +7 -13
- package/dist/default-config.js +16 -24
- package/dist/global-active-context.d.ts +2 -2
- package/dist/global-active-context.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/language-codes.d.ts +27 -0
- package/dist/language-codes.js +31 -0
- package/dist/registry-error.d.ts +2 -2
- package/dist/typed-error.d.ts +6 -6
- package/dist/typed-error.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,38 +49,36 @@ npm install @digitaldefiance/i18n-lib
|
|
|
49
49
|
```typescript
|
|
50
50
|
import { I18nEngine, I18nConfig, createContext, CurrencyCode, Timezone } from '@digitaldefiance/i18n-lib';
|
|
51
51
|
|
|
52
|
-
// Define your
|
|
52
|
+
// Define your string keys
|
|
53
53
|
enum MyStrings {
|
|
54
54
|
Welcome = 'welcome',
|
|
55
55
|
UserGreetingTemplate = 'userGreetingTemplate'
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Spanish = 'Spanish'
|
|
61
|
-
}
|
|
58
|
+
// Define your language codes (or use string literals)
|
|
59
|
+
type MyLanguages = 'en-US' | 'es';
|
|
62
60
|
|
|
63
61
|
// Configure the engine
|
|
64
62
|
const config: I18nConfig<MyStrings, MyLanguages> = {
|
|
65
63
|
stringNames: Object.values(MyStrings),
|
|
66
64
|
strings: {
|
|
67
|
-
|
|
65
|
+
'en-US': {
|
|
68
66
|
[MyStrings.Welcome]: 'Welcome!',
|
|
69
67
|
[MyStrings.UserGreetingTemplate]: 'Hello, {name}!'
|
|
70
68
|
},
|
|
71
|
-
|
|
69
|
+
'es': {
|
|
72
70
|
[MyStrings.Welcome]: '¡Bienvenido!',
|
|
73
71
|
[MyStrings.UserGreetingTemplate]: '¡Hola, {name}!'
|
|
74
72
|
}
|
|
75
73
|
},
|
|
76
|
-
defaultLanguage:
|
|
74
|
+
defaultLanguage: 'en-US',
|
|
77
75
|
defaultTranslationContext: 'user',
|
|
78
76
|
defaultCurrencyCode: new CurrencyCode('USD'),
|
|
79
77
|
languageCodes: {
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
'en-US': 'en-US',
|
|
79
|
+
'es': 'es'
|
|
82
80
|
},
|
|
83
|
-
languages:
|
|
81
|
+
languages: ['en-US', 'es'],
|
|
84
82
|
timezone: new Timezone('UTC'),
|
|
85
83
|
adminTimezone: new Timezone('UTC')
|
|
86
84
|
};
|
|
@@ -96,7 +94,7 @@ const greeting = i18n.translate(MyStrings.UserGreetingTemplate, { name: 'John' }
|
|
|
96
94
|
// "Hello, John!"
|
|
97
95
|
|
|
98
96
|
// Change language
|
|
99
|
-
i18n.context = { language:
|
|
97
|
+
i18n.context = { language: 'es' };
|
|
100
98
|
const spanishGreeting = i18n.translate(MyStrings.UserGreetingTemplate, { name: 'Juan' });
|
|
101
99
|
// "¡Hola, Juan!"
|
|
102
100
|
```
|
|
@@ -111,7 +109,8 @@ The new plugin-based architecture provides a component registration system with
|
|
|
111
109
|
import {
|
|
112
110
|
createCoreI18nEngine,
|
|
113
111
|
CoreStringKey,
|
|
114
|
-
|
|
112
|
+
CoreLanguageCode,
|
|
113
|
+
LanguageCodes,
|
|
115
114
|
ComponentDefinition,
|
|
116
115
|
ComponentRegistration
|
|
117
116
|
} from '@digitaldefiance/i18n-lib';
|
|
@@ -138,26 +137,26 @@ const MyComponent: ComponentDefinition<MyComponentStringKey> = {
|
|
|
138
137
|
|
|
139
138
|
// Define translations for all supported languages
|
|
140
139
|
const myComponentStrings = {
|
|
141
|
-
[
|
|
140
|
+
[LanguageCodes.EN_US]: {
|
|
142
141
|
[MyComponentStringKey.Welcome]: 'Welcome to my component!',
|
|
143
142
|
[MyComponentStringKey.Goodbye]: 'Goodbye from my component!',
|
|
144
143
|
[MyComponentStringKey.UserGreetingTemplate]: 'Hello, {name}!'
|
|
145
144
|
},
|
|
146
|
-
[
|
|
145
|
+
[LanguageCodes.FR]: {
|
|
147
146
|
[MyComponentStringKey.Welcome]: 'Bienvenue dans mon composant !',
|
|
148
147
|
[MyComponentStringKey.Goodbye]: 'Au revoir de mon composant !',
|
|
149
148
|
[MyComponentStringKey.UserGreetingTemplate]: 'Bonjour, {name} !'
|
|
150
149
|
},
|
|
151
|
-
[
|
|
150
|
+
[LanguageCodes.ES]: {
|
|
152
151
|
[MyComponentStringKey.Welcome]: '¡Bienvenido a mi componente!',
|
|
153
152
|
[MyComponentStringKey.Goodbye]: '¡Adiós desde mi componente!',
|
|
154
153
|
[MyComponentStringKey.UserGreetingTemplate]: '¡Hola, {name}!'
|
|
155
154
|
}
|
|
156
|
-
// TypeScript ensures all
|
|
155
|
+
// TypeScript ensures all language codes are handled
|
|
157
156
|
};
|
|
158
157
|
|
|
159
158
|
// Register component (with validation)
|
|
160
|
-
const registration: ComponentRegistration<MyComponentStringKey,
|
|
159
|
+
const registration: ComponentRegistration<MyComponentStringKey, CoreLanguageCode> = {
|
|
161
160
|
component: MyComponent,
|
|
162
161
|
strings: myComponentStrings
|
|
163
162
|
};
|
|
@@ -174,7 +173,7 @@ const greeting = i18n.translate('my-component', MyComponentStringKey.UserGreetin
|
|
|
174
173
|
});
|
|
175
174
|
|
|
176
175
|
// Change language - affects all components
|
|
177
|
-
i18n.setLanguage(
|
|
176
|
+
i18n.setLanguage(LanguageCodes.FR);
|
|
178
177
|
const frenchWelcome = i18n.translate('my-component', MyComponentStringKey.Welcome);
|
|
179
178
|
// "Bienvenue dans mon composant !"
|
|
180
179
|
```
|
|
@@ -199,6 +198,17 @@ Provides essential system strings in 8 languages:
|
|
|
199
198
|
|
|
200
199
|
- English (US/UK), French, Spanish, German, Chinese (Simplified), Japanese, Ukrainian
|
|
201
200
|
|
|
201
|
+
**Language Codes**: Use `LanguageCodes` constants or define your own:
|
|
202
|
+
```typescript
|
|
203
|
+
import { LanguageCodes } from '@digitaldefiance/i18n-lib';
|
|
204
|
+
|
|
205
|
+
// Common codes provided
|
|
206
|
+
LanguageCodes.EN_US // 'en-US'
|
|
207
|
+
LanguageCodes.FR // 'fr'
|
|
208
|
+
LanguageCodes.ES // 'es'
|
|
209
|
+
// ... or use any string: 'custom-lang'
|
|
210
|
+
```
|
|
211
|
+
|
|
202
212
|
```typescript
|
|
203
213
|
import { createCoreI18nEngine, CoreStringKey } from '@digitaldefiance/i18n-lib';
|
|
204
214
|
|
|
@@ -207,23 +217,44 @@ const saveText = i18n.translate('core', CoreStringKey.Common_Save);
|
|
|
207
217
|
const errorMsg = i18n.translate('core', CoreStringKey.Error_ValidationFailed);
|
|
208
218
|
```
|
|
209
219
|
|
|
210
|
-
####
|
|
220
|
+
#### Custom Component Example
|
|
211
221
|
|
|
212
|
-
|
|
222
|
+
Create your own component with translations:
|
|
213
223
|
|
|
214
224
|
```typescript
|
|
215
225
|
import {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
226
|
+
ComponentDefinition,
|
|
227
|
+
ComponentRegistration,
|
|
228
|
+
LanguageCodes
|
|
219
229
|
} from '@digitaldefiance/i18n-lib';
|
|
220
230
|
|
|
221
|
-
|
|
222
|
-
|
|
231
|
+
enum UserStringKey {
|
|
232
|
+
Auth_Login = 'auth_login',
|
|
233
|
+
Error_UserNotFoundTemplate = 'error_user_not_found_template'
|
|
234
|
+
}
|
|
223
235
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
236
|
+
const userComponent: ComponentDefinition<UserStringKey> = {
|
|
237
|
+
id: 'user-system',
|
|
238
|
+
name: 'User System',
|
|
239
|
+
stringKeys: Object.values(UserStringKey)
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const registration: ComponentRegistration<UserStringKey, CoreLanguageCode> = {
|
|
243
|
+
component: userComponent,
|
|
244
|
+
strings: {
|
|
245
|
+
[LanguageCodes.EN_US]: {
|
|
246
|
+
[UserStringKey.Auth_Login]: 'Login',
|
|
247
|
+
[UserStringKey.Error_UserNotFoundTemplate]: 'User "{username}" not found'
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
i18n.registerComponent(registration);
|
|
253
|
+
|
|
254
|
+
// Use translations
|
|
255
|
+
const loginText = i18n.translate('user-system', UserStringKey.Auth_Login);
|
|
256
|
+
const userNotFound = i18n.translate(
|
|
257
|
+
'user-system',
|
|
227
258
|
UserStringKey.Error_UserNotFoundTemplate,
|
|
228
259
|
{ username: 'john_doe' }
|
|
229
260
|
);
|
|
@@ -299,18 +330,18 @@ const myComponent: ComponentDefinition<MyStrings> = {
|
|
|
299
330
|
};
|
|
300
331
|
|
|
301
332
|
// System has EN, FR, ES languages - component must provide translations for all three
|
|
302
|
-
const registration: ComponentRegistration<MyStrings,
|
|
333
|
+
const registration: ComponentRegistration<MyStrings, CoreLanguageCode> = {
|
|
303
334
|
component: myComponent,
|
|
304
335
|
strings: {
|
|
305
|
-
[
|
|
336
|
+
[LanguageCodes.EN_US]: {
|
|
306
337
|
[MyStrings.Welcome]: 'Welcome',
|
|
307
338
|
[MyStrings.Goodbye]: 'Goodbye'
|
|
308
339
|
},
|
|
309
|
-
[
|
|
340
|
+
[LanguageCodes.FR]: {
|
|
310
341
|
[MyStrings.Welcome]: 'Bienvenue',
|
|
311
342
|
[MyStrings.Goodbye]: 'Au revoir'
|
|
312
343
|
},
|
|
313
|
-
[
|
|
344
|
+
[LanguageCodes.ES]: {
|
|
314
345
|
[MyStrings.Welcome]: 'Bienvenido',
|
|
315
346
|
[MyStrings.Goodbye]: 'Adiós'
|
|
316
347
|
}
|
|
@@ -333,9 +364,9 @@ Components can support different subsets of system languages:
|
|
|
333
364
|
const componentA = {
|
|
334
365
|
component: { id: 'comp-a', name: 'Component A', stringKeys: ['hello'] },
|
|
335
366
|
strings: {
|
|
336
|
-
en: { hello: 'Hello' },
|
|
337
|
-
fr: { hello: 'Bonjour' },
|
|
338
|
-
es: { hello: 'Hola' }
|
|
367
|
+
'en-US': { hello: 'Hello' },
|
|
368
|
+
'fr': { hello: 'Bonjour' },
|
|
369
|
+
'es': { hello: 'Hola' }
|
|
339
370
|
}
|
|
340
371
|
};
|
|
341
372
|
|
|
@@ -343,8 +374,8 @@ const componentA = {
|
|
|
343
374
|
const componentB = {
|
|
344
375
|
component: { id: 'comp-b', name: 'Component B', stringKeys: ['save'] },
|
|
345
376
|
strings: {
|
|
346
|
-
en: { save: 'Save' },
|
|
347
|
-
de: { save: 'Speichern' }
|
|
377
|
+
'en-US': { save: 'Save' },
|
|
378
|
+
'de': { save: 'Speichern' }
|
|
348
379
|
}
|
|
349
380
|
};
|
|
350
381
|
|
|
@@ -353,23 +384,25 @@ i18n.registerComponent(componentA); // ✓ Complete
|
|
|
353
384
|
i18n.registerComponent(componentB); // ⚠ Missing FR, ES - uses fallback
|
|
354
385
|
|
|
355
386
|
// Usage automatically handles fallbacks
|
|
356
|
-
i18n.translate('comp-b', 'save', {}, 'fr'); // Returns 'Save' (
|
|
387
|
+
i18n.translate('comp-b', 'save', {}, 'fr'); // Returns 'Save' (en-US fallback)
|
|
357
388
|
```
|
|
358
389
|
|
|
359
390
|
#### Dynamic Language Addition
|
|
360
391
|
|
|
361
392
|
```typescript
|
|
393
|
+
import { createLanguageDefinition } from '@digitaldefiance/i18n-lib';
|
|
394
|
+
|
|
362
395
|
// Add new language to system
|
|
363
|
-
const germanLang =
|
|
396
|
+
const germanLang = createLanguageDefinition('de', 'Deutsch', 'de');
|
|
364
397
|
i18n.registerLanguage(germanLang);
|
|
365
398
|
|
|
366
399
|
// New component registrations now require German translations
|
|
367
400
|
const newRegistration = {
|
|
368
401
|
component: { id: 'new-comp', name: 'New Component', stringKeys: ['test'] },
|
|
369
402
|
strings: {
|
|
370
|
-
en: { test: 'Test' },
|
|
371
|
-
fr: { test: 'Test' },
|
|
372
|
-
es: { test: 'Prueba' }
|
|
403
|
+
'en-US': { test: 'Test' },
|
|
404
|
+
'fr': { test: 'Test' },
|
|
405
|
+
'es': { test: 'Prueba' }
|
|
373
406
|
// Missing 'de' - validation will flag this
|
|
374
407
|
}
|
|
375
408
|
};
|
|
@@ -402,7 +435,7 @@ const strictEngine = new PluginI18nEngine(languages, {
|
|
|
402
435
|
validation: {
|
|
403
436
|
requireCompleteStrings: true,
|
|
404
437
|
allowPartialRegistration: false,
|
|
405
|
-
fallbackLanguageId: 'en'
|
|
438
|
+
fallbackLanguageId: 'en-US'
|
|
406
439
|
}
|
|
407
440
|
});
|
|
408
441
|
```
|
|
@@ -428,7 +461,7 @@ For complete documentation on the plugin architecture, see [PLUGIN_ARCHITECTURE.
|
|
|
428
461
|
The `TranslatableGenericError` class provides a simple way to create errors with translated messages that work across any component:
|
|
429
462
|
|
|
430
463
|
```typescript
|
|
431
|
-
import { TranslatableGenericError, CoreStringKey,
|
|
464
|
+
import { TranslatableGenericError, CoreStringKey, LanguageCodes } from '@digitaldefiance/i18n-lib';
|
|
432
465
|
|
|
433
466
|
// Define your error string keys
|
|
434
467
|
enum UserErrorKey {
|
|
@@ -447,12 +480,12 @@ const userErrorComponent = {
|
|
|
447
480
|
const registration = {
|
|
448
481
|
component: userErrorComponent,
|
|
449
482
|
strings: {
|
|
450
|
-
en: {
|
|
483
|
+
'en-US': {
|
|
451
484
|
[UserErrorKey.UserNotFound]: 'User "{username}" not found',
|
|
452
485
|
[UserErrorKey.InvalidCredentials]: 'Invalid credentials provided',
|
|
453
486
|
[UserErrorKey.AccountLocked]: 'Account locked until {unlockTime}'
|
|
454
487
|
},
|
|
455
|
-
fr: {
|
|
488
|
+
'fr': {
|
|
456
489
|
[UserErrorKey.UserNotFound]: 'Utilisateur "{username}" introuvable',
|
|
457
490
|
[UserErrorKey.InvalidCredentials]: 'Identifiants invalides fournis',
|
|
458
491
|
[UserErrorKey.AccountLocked]: 'Compte verrouillé jusqu\'à {unlockTime}'
|
|
@@ -467,7 +500,7 @@ throw new TranslatableGenericError(
|
|
|
467
500
|
'user-errors',
|
|
468
501
|
UserErrorKey.UserNotFound,
|
|
469
502
|
{ username: 'john_doe' },
|
|
470
|
-
'en',
|
|
503
|
+
'en-US',
|
|
471
504
|
{ userId: 123 }, // metadata
|
|
472
505
|
'myapp' // engine instance key
|
|
473
506
|
);
|
|
@@ -496,7 +529,7 @@ throw new TranslatableGenericError(
|
|
|
496
529
|
'core',
|
|
497
530
|
CoreStringKey.Error_AccessDenied,
|
|
498
531
|
undefined,
|
|
499
|
-
|
|
532
|
+
LanguageCodes.EN_US,
|
|
500
533
|
{ requestId: '12345' },
|
|
501
534
|
'myapp'
|
|
502
535
|
);
|
|
@@ -1026,6 +1059,51 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
|
|
|
1026
1059
|
|
|
1027
1060
|
## ChangeLog
|
|
1028
1061
|
|
|
1062
|
+
### Version 1.2.1
|
|
1063
|
+
|
|
1064
|
+
- Thu Oct 23 2025 15:10:00 GMT-0700 (Pacific Daylight Time)
|
|
1065
|
+
- Update README
|
|
1066
|
+
|
|
1067
|
+
### Version 1.2.0
|
|
1068
|
+
|
|
1069
|
+
- Thu Oct 23 2025 14:13:00 GMT-0700 (Pacific Daylight Time)
|
|
1070
|
+
|
|
1071
|
+
#### Breaking Changes
|
|
1072
|
+
- **Removed `CoreLanguage` enum** - Replaced with `CoreLanguageCode` type and `LanguageCodes` constants
|
|
1073
|
+
- **Language identifiers now use BCP 47 codes** - Changed from descriptive names (e.g., `'English (US)'`) to standard codes (e.g., `'en-US'`)
|
|
1074
|
+
- **API changes**:
|
|
1075
|
+
- `CoreLanguage` → `CoreLanguageCode` (union type)
|
|
1076
|
+
- `DefaultLanguage` enum → `DefaultLanguageCode` type
|
|
1077
|
+
- All language references updated to use `LanguageCodes` constants
|
|
1078
|
+
|
|
1079
|
+
#### Added
|
|
1080
|
+
- **`LanguageCodes` constants object** - Provides standard BCP 47 language codes:
|
|
1081
|
+
- `EN_US`, `EN_GB`, `FR`, `ES`, `DE`, `ZH_CN`, `JA`, `UK`
|
|
1082
|
+
- **`LanguageDisplayNames` mapping** - Maps language codes to human-readable names
|
|
1083
|
+
- **`CommonLanguageCode` type** - Type for built-in language codes
|
|
1084
|
+
- **`LanguageCode` type** - Generic string type for custom language codes
|
|
1085
|
+
- **Custom language code support** - Any string can now be used as a language code
|
|
1086
|
+
|
|
1087
|
+
#### Changed
|
|
1088
|
+
- **Language code format** - All language identifiers now use BCP 47 standard (e.g., `'en-US'` instead of `'English (US)'`)
|
|
1089
|
+
- **Type system** - Languages are now string-based types instead of enums, allowing custom language codes
|
|
1090
|
+
- **Documentation** - Updated README with new API usage examples and language code constants
|
|
1091
|
+
|
|
1092
|
+
#### Migration Guide
|
|
1093
|
+
```typescript
|
|
1094
|
+
// Before (v1.1.x)
|
|
1095
|
+
import { CoreLanguage } from '@digitaldefiance/i18n-lib';
|
|
1096
|
+
i18n.setLanguage(CoreLanguage.French);
|
|
1097
|
+
|
|
1098
|
+
// After
|
|
1099
|
+
import { LanguageCodes } from '@digitaldefiance/i18n-lib';
|
|
1100
|
+
i18n.setLanguage(LanguageCodes.FR);
|
|
1101
|
+
|
|
1102
|
+
// Extending with custom language codes
|
|
1103
|
+
type MyLanguageCodes = CoreLanguageCode | 'pt-BR' | 'it';
|
|
1104
|
+
const myEngine = PluginI18nEngine.createInstance<MyLanguageCodes>('custom', languages);
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1029
1107
|
### Version 1.1.10
|
|
1030
1108
|
|
|
1031
1109
|
- Fri Oct 17 2025 15:02:00 GMT-0700 (Pacific Daylight Time)
|
package/dist/core-i18n.d.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { ComponentDefinition } from './component-definition';
|
|
5
5
|
import { ComponentRegistration } from './component-registration';
|
|
6
|
-
import { CoreLanguage } from './core-language';
|
|
7
6
|
import { CoreStringKey } from './core-string-key';
|
|
7
|
+
import { LanguageCodes } from './language-codes';
|
|
8
8
|
import { LanguageDefinition } from './language-definition';
|
|
9
9
|
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
10
|
+
export type CoreLanguageCode = typeof LanguageCodes.EN_US | typeof LanguageCodes.EN_GB | typeof LanguageCodes.FR | typeof LanguageCodes.ES | typeof LanguageCodes.DE | typeof LanguageCodes.ZH_CN | typeof LanguageCodes.JA | typeof LanguageCodes.UK;
|
|
10
11
|
/**
|
|
11
12
|
* Create default language definitions
|
|
12
13
|
*/
|
|
@@ -19,24 +20,24 @@ export declare const CoreComponentDefinition: ComponentDefinition<CoreStringKey>
|
|
|
19
20
|
/**
|
|
20
21
|
* Core component strings for all default languages
|
|
21
22
|
*/
|
|
22
|
-
export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey,
|
|
23
|
+
export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey, CoreLanguageCode>;
|
|
23
24
|
/**
|
|
24
25
|
* Create core component registration
|
|
25
26
|
*/
|
|
26
|
-
export declare function createCoreComponentRegistration(): ComponentRegistration<CoreStringKey,
|
|
27
|
+
export declare function createCoreComponentRegistration(): ComponentRegistration<CoreStringKey, CoreLanguageCode>;
|
|
27
28
|
/**
|
|
28
29
|
* Create a pre-configured I18n engine with core components
|
|
29
30
|
*/
|
|
30
|
-
export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<
|
|
31
|
+
export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<CoreLanguageCode>;
|
|
31
32
|
/**
|
|
32
33
|
* Type alias for easier usage
|
|
33
34
|
*/
|
|
34
|
-
export type CoreI18nEngine = PluginI18nEngine<
|
|
35
|
+
export type CoreI18nEngine = PluginI18nEngine<CoreLanguageCode>;
|
|
35
36
|
/**
|
|
36
37
|
* Helper function to get core translation
|
|
37
38
|
*/
|
|
38
|
-
export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?:
|
|
39
|
+
export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: CoreLanguageCode, instanceKey?: string): string;
|
|
39
40
|
/**
|
|
40
41
|
* Helper function to safely get core translation with fallback
|
|
41
42
|
*/
|
|
42
|
-
export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?:
|
|
43
|
+
export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: CoreLanguageCode, instanceKey?: string): string;
|
package/dist/core-i18n.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.createCoreComponentRegistration = createCoreComponentRegistration;
|
|
|
10
10
|
exports.createCoreI18nEngine = createCoreI18nEngine;
|
|
11
11
|
exports.getCoreTranslation = getCoreTranslation;
|
|
12
12
|
exports.safeCoreTranslation = safeCoreTranslation;
|
|
13
|
-
const core_language_1 = require("./core-language");
|
|
14
13
|
const core_string_key_1 = require("./core-string-key");
|
|
14
|
+
const language_codes_1 = require("./language-codes");
|
|
15
15
|
const language_registry_1 = require("./language-registry");
|
|
16
16
|
const plugin_i18n_engine_1 = require("./plugin-i18n-engine");
|
|
17
17
|
const strict_types_1 = require("./strict-types");
|
|
@@ -22,43 +22,43 @@ const DefaultInstanceKey = 'default';
|
|
|
22
22
|
function createDefaultLanguages() {
|
|
23
23
|
return (0, language_registry_1.createLanguageDefinitions)([
|
|
24
24
|
{
|
|
25
|
-
id:
|
|
25
|
+
id: language_codes_1.LanguageCodes.EN_US,
|
|
26
26
|
name: 'English (US)',
|
|
27
27
|
code: 'en-US',
|
|
28
28
|
isDefault: true,
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
id:
|
|
31
|
+
id: language_codes_1.LanguageCodes.EN_GB,
|
|
32
32
|
name: 'English (UK)',
|
|
33
33
|
code: 'en-GB',
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
id:
|
|
36
|
+
id: language_codes_1.LanguageCodes.FR,
|
|
37
37
|
name: 'Français',
|
|
38
38
|
code: 'fr',
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
id:
|
|
41
|
+
id: language_codes_1.LanguageCodes.ES,
|
|
42
42
|
name: 'Español',
|
|
43
43
|
code: 'es',
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
|
-
id:
|
|
46
|
+
id: language_codes_1.LanguageCodes.DE,
|
|
47
47
|
name: 'Deutsch',
|
|
48
48
|
code: 'de',
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
|
-
id:
|
|
51
|
+
id: language_codes_1.LanguageCodes.ZH_CN,
|
|
52
52
|
name: '中文 (简体)',
|
|
53
53
|
code: 'zh-CN',
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
|
-
id:
|
|
56
|
+
id: language_codes_1.LanguageCodes.JA,
|
|
57
57
|
name: '日本語',
|
|
58
58
|
code: 'ja',
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
id:
|
|
61
|
+
id: language_codes_1.LanguageCodes.UK,
|
|
62
62
|
name: 'Українська',
|
|
63
63
|
code: 'uk',
|
|
64
64
|
},
|
|
@@ -78,7 +78,7 @@ exports.CoreComponentDefinition = {
|
|
|
78
78
|
*/
|
|
79
79
|
function createCoreComponentStrings() {
|
|
80
80
|
return (0, strict_types_1.createCompleteComponentStrings)({
|
|
81
|
-
[
|
|
81
|
+
[language_codes_1.LanguageCodes.EN_US]: {
|
|
82
82
|
// Common/General
|
|
83
83
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Yes',
|
|
84
84
|
[core_string_key_1.CoreStringKey.Common_No]: 'No',
|
|
@@ -121,7 +121,7 @@ function createCoreComponentStrings() {
|
|
|
121
121
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Operation completed successfully',
|
|
122
122
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'No data available',
|
|
123
123
|
},
|
|
124
|
-
[
|
|
124
|
+
[language_codes_1.LanguageCodes.EN_GB]: {
|
|
125
125
|
// Common/General (mostly same as US English)
|
|
126
126
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Yes',
|
|
127
127
|
[core_string_key_1.CoreStringKey.Common_No]: 'No',
|
|
@@ -164,7 +164,7 @@ function createCoreComponentStrings() {
|
|
|
164
164
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Operation completed successfully',
|
|
165
165
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'No data available',
|
|
166
166
|
},
|
|
167
|
-
[
|
|
167
|
+
[language_codes_1.LanguageCodes.FR]: {
|
|
168
168
|
// Common/General
|
|
169
169
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Oui',
|
|
170
170
|
[core_string_key_1.CoreStringKey.Common_No]: 'Non',
|
|
@@ -207,7 +207,7 @@ function createCoreComponentStrings() {
|
|
|
207
207
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Opération terminée avec succès',
|
|
208
208
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'Aucune donnée disponible',
|
|
209
209
|
},
|
|
210
|
-
[
|
|
210
|
+
[language_codes_1.LanguageCodes.ES]: {
|
|
211
211
|
// Common/General
|
|
212
212
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Sí',
|
|
213
213
|
[core_string_key_1.CoreStringKey.Common_No]: 'No',
|
|
@@ -250,7 +250,7 @@ function createCoreComponentStrings() {
|
|
|
250
250
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Operación completada exitosamente',
|
|
251
251
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'No hay datos disponibles',
|
|
252
252
|
},
|
|
253
|
-
[
|
|
253
|
+
[language_codes_1.LanguageCodes.DE]: {
|
|
254
254
|
// Common/General
|
|
255
255
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Ja',
|
|
256
256
|
[core_string_key_1.CoreStringKey.Common_No]: 'Nein',
|
|
@@ -293,7 +293,7 @@ function createCoreComponentStrings() {
|
|
|
293
293
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Vorgang erfolgreich abgeschlossen',
|
|
294
294
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'Keine Daten verfügbar',
|
|
295
295
|
},
|
|
296
|
-
[
|
|
296
|
+
[language_codes_1.LanguageCodes.ZH_CN]: {
|
|
297
297
|
// Common/General
|
|
298
298
|
[core_string_key_1.CoreStringKey.Common_Yes]: '是',
|
|
299
299
|
[core_string_key_1.CoreStringKey.Common_No]: '否',
|
|
@@ -336,7 +336,7 @@ function createCoreComponentStrings() {
|
|
|
336
336
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: '操作成功完成',
|
|
337
337
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: '无可用数据',
|
|
338
338
|
},
|
|
339
|
-
[
|
|
339
|
+
[language_codes_1.LanguageCodes.JA]: {
|
|
340
340
|
// Common/General
|
|
341
341
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'はい',
|
|
342
342
|
[core_string_key_1.CoreStringKey.Common_No]: 'いいえ',
|
|
@@ -379,7 +379,7 @@ function createCoreComponentStrings() {
|
|
|
379
379
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: '操作が正常に完了しました',
|
|
380
380
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: '利用可能なデータがありません',
|
|
381
381
|
},
|
|
382
|
-
[
|
|
382
|
+
[language_codes_1.LanguageCodes.UK]: {
|
|
383
383
|
// Common/General
|
|
384
384
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Так',
|
|
385
385
|
[core_string_key_1.CoreStringKey.Common_No]: 'Ні',
|
package/dist/default-config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { I18nContext } from './i18n-context';
|
|
2
2
|
import { I18nEngine } from './i18n-engine';
|
|
3
|
+
import { LanguageCodes } from './language-codes';
|
|
3
4
|
import { Timezone } from './timezone';
|
|
4
5
|
import { LanguageCodeCollection } from './types';
|
|
5
6
|
export declare enum DefaultStringKey {
|
|
@@ -11,21 +12,14 @@ export declare enum DefaultStringKey {
|
|
|
11
12
|
Error_DefaultLanguageNoCollectionTemplate = "error_defaultLanguageNoCollectionTemplate",
|
|
12
13
|
Error_MissingTranslationKeyTemplate = "error_missingTranslationKeyTemplate"
|
|
13
14
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
EnglishUK = "English (UK)",
|
|
17
|
-
French = "Fran\u00E7ais",
|
|
18
|
-
MandarinChinese = "\u4E2D\u6587",
|
|
19
|
-
Spanish = "Espa\u00F1ol",
|
|
20
|
-
Ukrainian = "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0438\u0439"
|
|
21
|
-
}
|
|
22
|
-
export declare const DefaultLanguageCodes: LanguageCodeCollection<DefaultLanguage>;
|
|
15
|
+
export type DefaultLanguageCode = typeof LanguageCodes.EN_US | typeof LanguageCodes.EN_GB | typeof LanguageCodes.FR | typeof LanguageCodes.ES | typeof LanguageCodes.ZH_CN | typeof LanguageCodes.UK;
|
|
16
|
+
export declare const DefaultLanguageCodes: LanguageCodeCollection<DefaultLanguageCode>;
|
|
23
17
|
declare global {
|
|
24
18
|
namespace I18n {
|
|
25
19
|
interface Config {
|
|
26
20
|
StringKey: DefaultStringKey;
|
|
27
|
-
Language:
|
|
28
|
-
LanguageCodes: LanguageCodeCollection<
|
|
21
|
+
Language: DefaultLanguageCode;
|
|
22
|
+
LanguageCodes: LanguageCodeCollection<DefaultLanguageCode>;
|
|
29
23
|
engine: I18nEngine<I18n.Config['StringKey'], I18n.Config['Language'], Record<any, any>, string>;
|
|
30
24
|
}
|
|
31
25
|
}
|
|
@@ -33,6 +27,6 @@ declare global {
|
|
|
33
27
|
export type StringKey = I18n.Config['StringKey'];
|
|
34
28
|
export type Language = I18n.Config['Language'];
|
|
35
29
|
export type Engine = I18n.Config['engine'];
|
|
36
|
-
export type
|
|
30
|
+
export type DefaultLanguageCodesType = I18n.Config['LanguageCodes'];
|
|
37
31
|
export declare const getI18nEngine: () => Engine;
|
|
38
|
-
export declare const getDefaultI18nEngine: <TConstants extends Record<string, any>, TTranslationContext extends string, TContext extends I18nContext<
|
|
32
|
+
export declare const getDefaultI18nEngine: <TConstants extends Record<string, any>, TTranslationContext extends string, TContext extends I18nContext<DefaultLanguageCode, TTranslationContext>>(constants: TConstants, timezone?: Timezone, adminTimezone?: Timezone) => I18nEngine<DefaultStringKey, DefaultLanguageCode, TConstants, TTranslationContext, TContext>;
|
package/dist/default-config.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultI18nEngine = exports.getI18nEngine = exports.DefaultLanguageCodes = exports.
|
|
3
|
+
exports.getDefaultI18nEngine = exports.getI18nEngine = exports.DefaultLanguageCodes = exports.DefaultStringKey = void 0;
|
|
4
4
|
const currency_code_1 = require("./currency-code");
|
|
5
5
|
const i18n_engine_1 = require("./i18n-engine");
|
|
6
|
+
const language_codes_1 = require("./language-codes");
|
|
6
7
|
const timezone_1 = require("./timezone");
|
|
7
8
|
const types_1 = require("./types");
|
|
8
9
|
// Default enum types that can be augmented by consumers
|
|
@@ -16,29 +17,20 @@ var DefaultStringKey;
|
|
|
16
17
|
DefaultStringKey["Error_DefaultLanguageNoCollectionTemplate"] = "error_defaultLanguageNoCollectionTemplate";
|
|
17
18
|
DefaultStringKey["Error_MissingTranslationKeyTemplate"] = "error_missingTranslationKeyTemplate";
|
|
18
19
|
})(DefaultStringKey || (exports.DefaultStringKey = DefaultStringKey = {}));
|
|
19
|
-
var DefaultLanguage;
|
|
20
|
-
(function (DefaultLanguage) {
|
|
21
|
-
DefaultLanguage["EnglishUS"] = "English (US)";
|
|
22
|
-
DefaultLanguage["EnglishUK"] = "English (UK)";
|
|
23
|
-
DefaultLanguage["French"] = "Fran\u00E7ais";
|
|
24
|
-
DefaultLanguage["MandarinChinese"] = "\u4E2D\u6587";
|
|
25
|
-
DefaultLanguage["Spanish"] = "Espa\u00F1ol";
|
|
26
|
-
DefaultLanguage["Ukrainian"] = "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0438\u0439";
|
|
27
|
-
})(DefaultLanguage || (exports.DefaultLanguage = DefaultLanguage = {}));
|
|
28
20
|
exports.DefaultLanguageCodes = {
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
21
|
+
[language_codes_1.LanguageCodes.EN_US]: 'en-US',
|
|
22
|
+
[language_codes_1.LanguageCodes.EN_GB]: 'en-GB',
|
|
23
|
+
[language_codes_1.LanguageCodes.FR]: 'fr',
|
|
24
|
+
[language_codes_1.LanguageCodes.ES]: 'es',
|
|
25
|
+
[language_codes_1.LanguageCodes.ZH_CN]: 'zh-CN',
|
|
26
|
+
[language_codes_1.LanguageCodes.UK]: 'uk',
|
|
35
27
|
};
|
|
36
28
|
// Singleton instance that uses the augmented types
|
|
37
29
|
const getI18nEngine = () => i18n_engine_1.I18nEngine.getInstance();
|
|
38
30
|
exports.getI18nEngine = getI18nEngine;
|
|
39
31
|
const getConfig = (constants, timezone, adminTimezone) => ({
|
|
40
32
|
strings: {
|
|
41
|
-
[
|
|
33
|
+
[language_codes_1.LanguageCodes.EN_US]: {
|
|
42
34
|
[DefaultStringKey.Common_Test]: 'Test',
|
|
43
35
|
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: "Instance with key '{key}' already exists",
|
|
44
36
|
[DefaultStringKey.Error_InstanceNotFoundTemplate]: "Instance with key '{key}' not found",
|
|
@@ -47,7 +39,7 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
47
39
|
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: "Default language '{language}' has no string collection",
|
|
48
40
|
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Missing translation key for type: {type}',
|
|
49
41
|
},
|
|
50
|
-
[
|
|
42
|
+
[language_codes_1.LanguageCodes.EN_GB]: {
|
|
51
43
|
[DefaultStringKey.Common_Test]: 'Test',
|
|
52
44
|
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: "Instance with key '{key}' already exists",
|
|
53
45
|
[DefaultStringKey.Error_InstanceNotFoundTemplate]: "Instance with key '{key}' not found",
|
|
@@ -56,7 +48,7 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
56
48
|
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: "Default language '{language}' has no string collection",
|
|
57
49
|
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Missing translation key for type: {type}',
|
|
58
50
|
},
|
|
59
|
-
[
|
|
51
|
+
[language_codes_1.LanguageCodes.FR]: {
|
|
60
52
|
[DefaultStringKey.Common_Test]: 'Test',
|
|
61
53
|
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: "Instance avec clé '{key}' existe déjà",
|
|
62
54
|
[DefaultStringKey.Error_InstanceNotFoundTemplate]: "Instance avec clé '{key}' introuvable",
|
|
@@ -65,7 +57,7 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
65
57
|
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: "La langue par défaut '{language}' n'a pas de collection de chaînes",
|
|
66
58
|
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Clé de traduction manquante pour le type: {type}',
|
|
67
59
|
},
|
|
68
|
-
[
|
|
60
|
+
[language_codes_1.LanguageCodes.ZH_CN]: {
|
|
69
61
|
[DefaultStringKey.Common_Test]: '测试',
|
|
70
62
|
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: "键为'{key}'的实例已存在",
|
|
71
63
|
[DefaultStringKey.Error_InstanceNotFoundTemplate]: "未找到键为'{key}'的实例",
|
|
@@ -74,7 +66,7 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
74
66
|
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: "默认语言'{language}'没有字符串集合",
|
|
75
67
|
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: '类型缺少翻译键: {type}',
|
|
76
68
|
},
|
|
77
|
-
[
|
|
69
|
+
[language_codes_1.LanguageCodes.ES]: {
|
|
78
70
|
[DefaultStringKey.Common_Test]: 'Prueba',
|
|
79
71
|
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: "La instancia con clave '{key}' ya existe",
|
|
80
72
|
[DefaultStringKey.Error_InstanceNotFoundTemplate]: "Instancia con clave '{key}' no encontrada",
|
|
@@ -83,7 +75,7 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
83
75
|
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: "El idioma predeterminado '{language}' no tiene colección de cadenas",
|
|
84
76
|
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Falta clave de traducción para el tipo: {type}',
|
|
85
77
|
},
|
|
86
|
-
[
|
|
78
|
+
[language_codes_1.LanguageCodes.UK]: {
|
|
87
79
|
[DefaultStringKey.Common_Test]: 'Тест',
|
|
88
80
|
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: "Екземпляр з ключем '{key}' вже існує",
|
|
89
81
|
[DefaultStringKey.Error_InstanceNotFoundTemplate]: "Екземпляр з ключем '{key}' не знайдено",
|
|
@@ -94,11 +86,11 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
94
86
|
},
|
|
95
87
|
},
|
|
96
88
|
stringNames: Object.values(DefaultStringKey),
|
|
97
|
-
defaultLanguage:
|
|
89
|
+
defaultLanguage: language_codes_1.LanguageCodes.EN_US,
|
|
98
90
|
defaultTranslationContext: 'user',
|
|
99
91
|
defaultCurrencyCode: new currency_code_1.CurrencyCode(types_1.DefaultCurrencyCode),
|
|
100
92
|
languageCodes: exports.DefaultLanguageCodes,
|
|
101
|
-
languages:
|
|
93
|
+
languages: [language_codes_1.LanguageCodes.EN_US, language_codes_1.LanguageCodes.EN_GB, language_codes_1.LanguageCodes.FR, language_codes_1.LanguageCodes.ES, language_codes_1.LanguageCodes.ZH_CN, language_codes_1.LanguageCodes.UK],
|
|
102
94
|
constants: constants,
|
|
103
95
|
enumName: 'DefaultStringKey',
|
|
104
96
|
enumObj: DefaultStringKey,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IActiveContext } from './active-context';
|
|
2
2
|
import { CurrencyCode } from './currency-code';
|
|
3
|
-
import {
|
|
3
|
+
import { DefaultLanguageCode } from './default-config';
|
|
4
4
|
import { IGlobalActiveContext } from './i-global-active-context';
|
|
5
5
|
import { Timezone } from './timezone';
|
|
6
6
|
import { LanguageContextSpace } from './types';
|
|
7
7
|
export declare class GlobalActiveContext<TLanguage extends string, TActiveContext extends IActiveContext<TLanguage>> implements IGlobalActiveContext<TLanguage, TActiveContext> {
|
|
8
8
|
protected static _contextMap: Map<string, IActiveContext<any>>;
|
|
9
9
|
static readonly defaultContextKey = "default";
|
|
10
|
-
static readonly defaultLanguage:
|
|
10
|
+
static readonly defaultLanguage: DefaultLanguageCode;
|
|
11
11
|
private static _instance;
|
|
12
12
|
static get instance(): GlobalActiveContext<any, any>;
|
|
13
13
|
static getInstance<TLanguage extends string, TActiveContext extends IActiveContext<TLanguage>>(): GlobalActiveContext<TLanguage, TActiveContext>;
|
|
@@ -4,7 +4,6 @@ exports.GlobalActiveContext = void 0;
|
|
|
4
4
|
const context_error_1 = require("./context-error");
|
|
5
5
|
const context_error_type_1 = require("./context-error-type");
|
|
6
6
|
const currency_code_1 = require("./currency-code");
|
|
7
|
-
const default_config_1 = require("./default-config");
|
|
8
7
|
const timezone_1 = require("./timezone");
|
|
9
8
|
const types_1 = require("./types");
|
|
10
9
|
class GlobalActiveContext {
|
|
@@ -168,4 +167,4 @@ class GlobalActiveContext {
|
|
|
168
167
|
exports.GlobalActiveContext = GlobalActiveContext;
|
|
169
168
|
GlobalActiveContext._contextMap = new Map();
|
|
170
169
|
GlobalActiveContext.defaultContextKey = 'default';
|
|
171
|
-
GlobalActiveContext.defaultLanguage =
|
|
170
|
+
GlobalActiveContext.defaultLanguage = 'en-US';
|
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export * from './utils';
|
|
|
25
25
|
export * from './validation-config';
|
|
26
26
|
export * from './validation-result';
|
|
27
27
|
export * from './core-i18n';
|
|
28
|
-
export * from './core-language';
|
|
29
28
|
export * from './core-string-key';
|
|
29
|
+
export * from './language-codes';
|
|
30
30
|
export * from './language-registry';
|
|
31
31
|
export * from './plugin-i18n-engine';
|
|
32
32
|
export * from './registry-config';
|
package/dist/index.js
CHANGED
|
@@ -44,8 +44,8 @@ __exportStar(require("./utils"), exports);
|
|
|
44
44
|
__exportStar(require("./validation-config"), exports);
|
|
45
45
|
__exportStar(require("./validation-result"), exports);
|
|
46
46
|
__exportStar(require("./core-i18n"), exports);
|
|
47
|
-
__exportStar(require("./core-language"), exports);
|
|
48
47
|
__exportStar(require("./core-string-key"), exports);
|
|
48
|
+
__exportStar(require("./language-codes"), exports);
|
|
49
49
|
__exportStar(require("./language-registry"), exports);
|
|
50
50
|
__exportStar(require("./plugin-i18n-engine"), exports);
|
|
51
51
|
__exportStar(require("./registry-config"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common language codes following BCP 47 standard.
|
|
3
|
+
* These are provided as constants for convenience, but any string can be used as a language code.
|
|
4
|
+
* Site builders can use these or define their own custom language codes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const LanguageCodes: {
|
|
7
|
+
readonly EN_US: "en-US";
|
|
8
|
+
readonly EN_GB: "en-GB";
|
|
9
|
+
readonly FR: "fr";
|
|
10
|
+
readonly ES: "es";
|
|
11
|
+
readonly DE: "de";
|
|
12
|
+
readonly ZH_CN: "zh-CN";
|
|
13
|
+
readonly JA: "ja";
|
|
14
|
+
readonly UK: "uk";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Type representing any language code (string)
|
|
18
|
+
*/
|
|
19
|
+
export type LanguageCode = string;
|
|
20
|
+
/**
|
|
21
|
+
* Type representing the common language codes provided by this library
|
|
22
|
+
*/
|
|
23
|
+
export type CommonLanguageCode = typeof LanguageCodes[keyof typeof LanguageCodes];
|
|
24
|
+
/**
|
|
25
|
+
* Helper to get display names for common language codes
|
|
26
|
+
*/
|
|
27
|
+
export declare const LanguageDisplayNames: Record<CommonLanguageCode, string>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LanguageDisplayNames = exports.LanguageCodes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Common language codes following BCP 47 standard.
|
|
6
|
+
* These are provided as constants for convenience, but any string can be used as a language code.
|
|
7
|
+
* Site builders can use these or define their own custom language codes.
|
|
8
|
+
*/
|
|
9
|
+
exports.LanguageCodes = {
|
|
10
|
+
EN_US: 'en-US',
|
|
11
|
+
EN_GB: 'en-GB',
|
|
12
|
+
FR: 'fr',
|
|
13
|
+
ES: 'es',
|
|
14
|
+
DE: 'de',
|
|
15
|
+
ZH_CN: 'zh-CN',
|
|
16
|
+
JA: 'ja',
|
|
17
|
+
UK: 'uk',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Helper to get display names for common language codes
|
|
21
|
+
*/
|
|
22
|
+
exports.LanguageDisplayNames = {
|
|
23
|
+
[exports.LanguageCodes.EN_US]: 'English (US)',
|
|
24
|
+
[exports.LanguageCodes.EN_GB]: 'English (UK)',
|
|
25
|
+
[exports.LanguageCodes.FR]: 'Français',
|
|
26
|
+
[exports.LanguageCodes.ES]: 'Español',
|
|
27
|
+
[exports.LanguageCodes.DE]: 'Deutsch',
|
|
28
|
+
[exports.LanguageCodes.ZH_CN]: '中文',
|
|
29
|
+
[exports.LanguageCodes.JA]: '日本語',
|
|
30
|
+
[exports.LanguageCodes.UK]: 'Українська',
|
|
31
|
+
};
|
package/dist/registry-error.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CoreLanguageCode } from './core-i18n';
|
|
2
2
|
import { RegistryErrorType } from './registry-error-type';
|
|
3
3
|
import { TranslationEngine } from './typed-error';
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ export declare class RegistryError extends Error {
|
|
|
11
11
|
/**
|
|
12
12
|
* Create a registry error with translation support
|
|
13
13
|
*/
|
|
14
|
-
static createWithEngine(engine: TranslationEngine, type: RegistryErrorType, variables?: Record<string, string | number>, language?:
|
|
14
|
+
static createWithEngine(engine: TranslationEngine, type: RegistryErrorType, variables?: Record<string, string | number>, language?: CoreLanguageCode, metadata?: Record<string, any>): RegistryError;
|
|
15
15
|
/**
|
|
16
16
|
* Create a simple RegistryError without engine dependency
|
|
17
17
|
*/
|
package/dist/typed-error.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Language, StringKey } from './default-config';
|
|
2
2
|
import { I18nEngine } from './i18n-engine';
|
|
3
|
-
import {
|
|
3
|
+
import { CoreLanguageCode } from './core-i18n';
|
|
4
4
|
import { CoreStringKey } from './core-string-key';
|
|
5
5
|
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
6
6
|
/**
|
|
@@ -42,7 +42,7 @@ export declare abstract class TypedError<TEnum extends Record<string, string>, T
|
|
|
42
42
|
/**
|
|
43
43
|
* Plugin-based TypedError that works with the new component registration system
|
|
44
44
|
*/
|
|
45
|
-
export declare abstract class PluginTypedError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string =
|
|
45
|
+
export declare abstract class PluginTypedError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string = string> extends Error {
|
|
46
46
|
readonly componentId: string;
|
|
47
47
|
readonly type: TEnum[keyof TEnum];
|
|
48
48
|
readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
|
|
@@ -56,18 +56,18 @@ export declare abstract class PluginTypedError<TEnum extends Record<string, stri
|
|
|
56
56
|
export declare abstract class CoreTypedError<TEnum extends Record<string, string>> extends Error {
|
|
57
57
|
readonly type: TEnum[keyof TEnum];
|
|
58
58
|
readonly reasonMap: CompleteReasonMap<TEnum, CoreStringKey>;
|
|
59
|
-
readonly language?:
|
|
59
|
+
readonly language?: CoreLanguageCode | undefined;
|
|
60
60
|
readonly otherVars?: Record<string, string | number> | undefined;
|
|
61
|
-
constructor(engine: PluginI18nEngine<
|
|
61
|
+
constructor(engine: PluginI18nEngine<CoreLanguageCode>, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, language?: CoreLanguageCode | undefined, otherVars?: Record<string, string | number> | undefined);
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Helper function to create a plugin-based TypedError with automatic engine detection
|
|
65
65
|
*/
|
|
66
|
-
export declare function createPluginTypedError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string =
|
|
66
|
+
export declare function createPluginTypedError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string = string>(componentId: string, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, otherVars?: Record<string, string | number>, language?: TLanguages, instanceKey?: string): Error;
|
|
67
67
|
/**
|
|
68
68
|
* Helper function to create a core system TypedError with automatic engine detection
|
|
69
69
|
*/
|
|
70
|
-
export declare function createCoreTypedError<TEnum extends Record<string, string>>(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, otherVars?: Record<string, string | number>, language?:
|
|
70
|
+
export declare function createCoreTypedError<TEnum extends Record<string, string>>(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, otherVars?: Record<string, string | number>, language?: CoreLanguageCode, instanceKey?: string): Error;
|
|
71
71
|
/**
|
|
72
72
|
* Create a simple error with translation support (generalized pattern from RegistryError)
|
|
73
73
|
*/
|
package/dist/typed-error.js
CHANGED
|
@@ -177,7 +177,7 @@ const coreErrorReasonMap: CompleteReasonMap<typeof DatabaseErrorType, CoreString
|
|
|
177
177
|
|
|
178
178
|
class DatabaseError extends CoreTypedError<typeof DatabaseErrorType> {
|
|
179
179
|
constructor(
|
|
180
|
-
engine: PluginI18nEngine<
|
|
180
|
+
engine: PluginI18nEngine<CoreLanguageCode>,
|
|
181
181
|
type: DatabaseErrorType,
|
|
182
182
|
otherVars?: Record<string, string | number>,
|
|
183
183
|
language?: CoreLanguage
|
|
@@ -187,7 +187,7 @@ class DatabaseError extends CoreTypedError<typeof DatabaseErrorType> {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// Usage:
|
|
190
|
-
// const engine = PluginI18nEngine.getInstance<
|
|
190
|
+
// const engine = PluginI18nEngine.getInstance<CoreLanguageCode>();
|
|
191
191
|
// throw new DatabaseError(engine, DatabaseErrorType.ConnectionFailed);
|
|
192
192
|
*/
|
|
193
193
|
// Example 2: Custom component error with custom strings
|
|
@@ -210,9 +210,9 @@ const userErrorReasonMap: CompleteReasonMap<typeof UserErrorType, UserErrorStrin
|
|
|
210
210
|
[UserErrorType.AccountLocked]: UserErrorStringKey.AccountLockedMessage
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
-
class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey,
|
|
213
|
+
class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey, CoreLanguageCode> {
|
|
214
214
|
constructor(
|
|
215
|
-
engine: PluginI18nEngine<
|
|
215
|
+
engine: PluginI18nEngine<CoreLanguageCode>,
|
|
216
216
|
type: UserErrorType,
|
|
217
217
|
otherVars?: Record<string, string | number>,
|
|
218
218
|
language?: CoreLanguage
|
|
@@ -222,7 +222,7 @@ class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKe
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// Usage:
|
|
225
|
-
// const engine = PluginI18nEngine.getInstance<
|
|
225
|
+
// const engine = PluginI18nEngine.getInstance<CoreLanguageCode>();
|
|
226
226
|
// throw new UserError(engine, UserErrorType.UserNotFound, { username: 'john_doe' });
|
|
227
227
|
*/
|
|
228
228
|
// Example 3: Using helper functions for simpler error creation
|