@digitaldefiance/i18n-lib 1.1.9 → 1.2.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 +74 -19
- package/dist/core-i18n.d.ts +8 -7
- package/dist/core-i18n.js +25 -17
- package/dist/core-string-key.d.ts +1 -0
- package/dist/core-string-key.js +1 -0
- 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/translatable-generic-error.js +0 -1
- 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
|
|
|
@@ -1026,6 +1036,51 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
|
|
|
1026
1036
|
|
|
1027
1037
|
## ChangeLog
|
|
1028
1038
|
|
|
1039
|
+
### Version 1.2.0
|
|
1040
|
+
|
|
1041
|
+
- Thu Oct 23 2025 14:13:00 GMT-0700 (Pacific Daylight Time)
|
|
1042
|
+
|
|
1043
|
+
#### Breaking Changes
|
|
1044
|
+
- **Removed `CoreLanguage` enum** - Replaced with `CoreLanguageCode` type and `LanguageCodes` constants
|
|
1045
|
+
- **Language identifiers now use BCP 47 codes** - Changed from descriptive names (e.g., `'English (US)'`) to standard codes (e.g., `'en-US'`)
|
|
1046
|
+
- **API changes**:
|
|
1047
|
+
- `CoreLanguage` → `CoreLanguageCode` (union type)
|
|
1048
|
+
- `DefaultLanguage` enum → `DefaultLanguageCode` type
|
|
1049
|
+
- All language references updated to use `LanguageCodes` constants
|
|
1050
|
+
|
|
1051
|
+
#### Added
|
|
1052
|
+
- **`LanguageCodes` constants object** - Provides standard BCP 47 language codes:
|
|
1053
|
+
- `EN_US`, `EN_GB`, `FR`, `ES`, `DE`, `ZH_CN`, `JA`, `UK`
|
|
1054
|
+
- **`LanguageDisplayNames` mapping** - Maps language codes to human-readable names
|
|
1055
|
+
- **`CommonLanguageCode` type** - Type for built-in language codes
|
|
1056
|
+
- **`LanguageCode` type** - Generic string type for custom language codes
|
|
1057
|
+
- **Custom language code support** - Any string can now be used as a language code
|
|
1058
|
+
|
|
1059
|
+
#### Changed
|
|
1060
|
+
- **Language code format** - All language identifiers now use BCP 47 standard (e.g., `'en-US'` instead of `'English (US)'`)
|
|
1061
|
+
- **Type system** - Languages are now string-based types instead of enums, allowing custom language codes
|
|
1062
|
+
- **Documentation** - Updated README with new API usage examples and language code constants
|
|
1063
|
+
|
|
1064
|
+
#### Migration Guide
|
|
1065
|
+
```typescript
|
|
1066
|
+
// Before
|
|
1067
|
+
import { CoreLanguage } from '@digitaldefiance/i18n-lib';
|
|
1068
|
+
i18n.setLanguage(CoreLanguage.French);
|
|
1069
|
+
|
|
1070
|
+
// After
|
|
1071
|
+
import { LanguageCodes } from '@digitaldefiance/i18n-lib';
|
|
1072
|
+
i18n.setLanguage(LanguageCodes.FR);
|
|
1073
|
+
|
|
1074
|
+
// Extending with custom language codes
|
|
1075
|
+
type MyLanguageCodes = CoreLanguageCode | 'pt-BR' | 'it';
|
|
1076
|
+
const myEngine = PluginI18nEngine.createInstance<MyLanguageCodes>('custom', languages);
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1079
|
+
### Version 1.1.10
|
|
1080
|
+
|
|
1081
|
+
- Fri Oct 17 2025 15:02:00 GMT-0700 (Pacific Daylight Time)
|
|
1082
|
+
- Add String
|
|
1083
|
+
|
|
1029
1084
|
### Version 1.1.9
|
|
1030
1085
|
|
|
1031
1086
|
- Fri Oct 17 2025 14:44: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',
|
|
@@ -94,6 +94,7 @@ function createCoreComponentStrings() {
|
|
|
94
94
|
[core_string_key_1.CoreStringKey.Common_Success]: 'Success',
|
|
95
95
|
[core_string_key_1.CoreStringKey.Common_Warning]: 'Warning',
|
|
96
96
|
[core_string_key_1.CoreStringKey.Common_Info]: 'Information',
|
|
97
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'Object has been disposed',
|
|
97
98
|
// Error Messages
|
|
98
99
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: 'Invalid input provided',
|
|
99
100
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: 'Network connection error',
|
|
@@ -120,7 +121,7 @@ function createCoreComponentStrings() {
|
|
|
120
121
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Operation completed successfully',
|
|
121
122
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'No data available',
|
|
122
123
|
},
|
|
123
|
-
[
|
|
124
|
+
[language_codes_1.LanguageCodes.EN_GB]: {
|
|
124
125
|
// Common/General (mostly same as US English)
|
|
125
126
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Yes',
|
|
126
127
|
[core_string_key_1.CoreStringKey.Common_No]: 'No',
|
|
@@ -136,6 +137,7 @@ function createCoreComponentStrings() {
|
|
|
136
137
|
[core_string_key_1.CoreStringKey.Common_Success]: 'Success',
|
|
137
138
|
[core_string_key_1.CoreStringKey.Common_Warning]: 'Warning',
|
|
138
139
|
[core_string_key_1.CoreStringKey.Common_Info]: 'Information',
|
|
140
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'Object has been disposed',
|
|
139
141
|
// Error Messages
|
|
140
142
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: 'Invalid input provided',
|
|
141
143
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: 'Network connection error',
|
|
@@ -162,7 +164,7 @@ function createCoreComponentStrings() {
|
|
|
162
164
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Operation completed successfully',
|
|
163
165
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'No data available',
|
|
164
166
|
},
|
|
165
|
-
[
|
|
167
|
+
[language_codes_1.LanguageCodes.FR]: {
|
|
166
168
|
// Common/General
|
|
167
169
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Oui',
|
|
168
170
|
[core_string_key_1.CoreStringKey.Common_No]: 'Non',
|
|
@@ -178,6 +180,7 @@ function createCoreComponentStrings() {
|
|
|
178
180
|
[core_string_key_1.CoreStringKey.Common_Success]: 'Succès',
|
|
179
181
|
[core_string_key_1.CoreStringKey.Common_Warning]: 'Avertissement',
|
|
180
182
|
[core_string_key_1.CoreStringKey.Common_Info]: 'Information',
|
|
183
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'L\'objet a été disposé',
|
|
181
184
|
// Error Messages
|
|
182
185
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: 'Entrée invalide fournie',
|
|
183
186
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: 'Erreur de connexion réseau',
|
|
@@ -204,7 +207,7 @@ function createCoreComponentStrings() {
|
|
|
204
207
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Opération terminée avec succès',
|
|
205
208
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'Aucune donnée disponible',
|
|
206
209
|
},
|
|
207
|
-
[
|
|
210
|
+
[language_codes_1.LanguageCodes.ES]: {
|
|
208
211
|
// Common/General
|
|
209
212
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Sí',
|
|
210
213
|
[core_string_key_1.CoreStringKey.Common_No]: 'No',
|
|
@@ -220,6 +223,7 @@ function createCoreComponentStrings() {
|
|
|
220
223
|
[core_string_key_1.CoreStringKey.Common_Success]: 'Éxito',
|
|
221
224
|
[core_string_key_1.CoreStringKey.Common_Warning]: 'Advertencia',
|
|
222
225
|
[core_string_key_1.CoreStringKey.Common_Info]: 'Información',
|
|
226
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'El objeto ha sido eliminado',
|
|
223
227
|
// Error Messages
|
|
224
228
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: 'Entrada inválida proporcionada',
|
|
225
229
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: 'Error de conexión de red',
|
|
@@ -246,7 +250,7 @@ function createCoreComponentStrings() {
|
|
|
246
250
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Operación completada exitosamente',
|
|
247
251
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'No hay datos disponibles',
|
|
248
252
|
},
|
|
249
|
-
[
|
|
253
|
+
[language_codes_1.LanguageCodes.DE]: {
|
|
250
254
|
// Common/General
|
|
251
255
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Ja',
|
|
252
256
|
[core_string_key_1.CoreStringKey.Common_No]: 'Nein',
|
|
@@ -262,6 +266,7 @@ function createCoreComponentStrings() {
|
|
|
262
266
|
[core_string_key_1.CoreStringKey.Common_Success]: 'Erfolg',
|
|
263
267
|
[core_string_key_1.CoreStringKey.Common_Warning]: 'Warnung',
|
|
264
268
|
[core_string_key_1.CoreStringKey.Common_Info]: 'Information',
|
|
269
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'Objekt wurde freigegeben',
|
|
265
270
|
// Error Messages
|
|
266
271
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: 'Ungültige Eingabe bereitgestellt',
|
|
267
272
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: 'Netzwerkverbindungsfehler',
|
|
@@ -288,7 +293,7 @@ function createCoreComponentStrings() {
|
|
|
288
293
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: 'Vorgang erfolgreich abgeschlossen',
|
|
289
294
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: 'Keine Daten verfügbar',
|
|
290
295
|
},
|
|
291
|
-
[
|
|
296
|
+
[language_codes_1.LanguageCodes.ZH_CN]: {
|
|
292
297
|
// Common/General
|
|
293
298
|
[core_string_key_1.CoreStringKey.Common_Yes]: '是',
|
|
294
299
|
[core_string_key_1.CoreStringKey.Common_No]: '否',
|
|
@@ -304,6 +309,7 @@ function createCoreComponentStrings() {
|
|
|
304
309
|
[core_string_key_1.CoreStringKey.Common_Success]: '成功',
|
|
305
310
|
[core_string_key_1.CoreStringKey.Common_Warning]: '警告',
|
|
306
311
|
[core_string_key_1.CoreStringKey.Common_Info]: '信息',
|
|
312
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: '对象已被释放',
|
|
307
313
|
// Error Messages
|
|
308
314
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: '提供的输入无效',
|
|
309
315
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: '网络连接错误',
|
|
@@ -330,7 +336,7 @@ function createCoreComponentStrings() {
|
|
|
330
336
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: '操作成功完成',
|
|
331
337
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: '无可用数据',
|
|
332
338
|
},
|
|
333
|
-
[
|
|
339
|
+
[language_codes_1.LanguageCodes.JA]: {
|
|
334
340
|
// Common/General
|
|
335
341
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'はい',
|
|
336
342
|
[core_string_key_1.CoreStringKey.Common_No]: 'いいえ',
|
|
@@ -346,6 +352,7 @@ function createCoreComponentStrings() {
|
|
|
346
352
|
[core_string_key_1.CoreStringKey.Common_Success]: '成功',
|
|
347
353
|
[core_string_key_1.CoreStringKey.Common_Warning]: '警告',
|
|
348
354
|
[core_string_key_1.CoreStringKey.Common_Info]: '情報',
|
|
355
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'オブジェクトは破棄されました',
|
|
349
356
|
// Error Messages
|
|
350
357
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: '無効な入力が提供されました',
|
|
351
358
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: 'ネットワーク接続エラー',
|
|
@@ -372,7 +379,7 @@ function createCoreComponentStrings() {
|
|
|
372
379
|
[core_string_key_1.CoreStringKey.System_OperationComplete]: '操作が正常に完了しました',
|
|
373
380
|
[core_string_key_1.CoreStringKey.System_NoDataAvailable]: '利用可能なデータがありません',
|
|
374
381
|
},
|
|
375
|
-
[
|
|
382
|
+
[language_codes_1.LanguageCodes.UK]: {
|
|
376
383
|
// Common/General
|
|
377
384
|
[core_string_key_1.CoreStringKey.Common_Yes]: 'Так',
|
|
378
385
|
[core_string_key_1.CoreStringKey.Common_No]: 'Ні',
|
|
@@ -388,6 +395,7 @@ function createCoreComponentStrings() {
|
|
|
388
395
|
[core_string_key_1.CoreStringKey.Common_Success]: 'Успіх',
|
|
389
396
|
[core_string_key_1.CoreStringKey.Common_Warning]: 'Попередження',
|
|
390
397
|
[core_string_key_1.CoreStringKey.Common_Info]: 'Інформація',
|
|
398
|
+
[core_string_key_1.CoreStringKey.Common_Disposed]: 'Об\'єкт було звільнено',
|
|
391
399
|
// Error Messages
|
|
392
400
|
[core_string_key_1.CoreStringKey.Error_InvalidInput]: 'Надано неправильний ввід',
|
|
393
401
|
[core_string_key_1.CoreStringKey.Error_NetworkError]: "Помилка мережевого з'єднання",
|
|
@@ -16,6 +16,7 @@ export declare enum CoreStringKey {
|
|
|
16
16
|
Common_Success = "common_success",
|
|
17
17
|
Common_Warning = "common_warning",
|
|
18
18
|
Common_Info = "common_info",
|
|
19
|
+
Common_Disposed = "common_disposed",
|
|
19
20
|
Error_InvalidInput = "error_invalidInput",
|
|
20
21
|
Error_NetworkError = "error_networkError",
|
|
21
22
|
Error_NotFound = "error_notFound",
|
package/dist/core-string-key.js
CHANGED
|
@@ -21,6 +21,7 @@ var CoreStringKey;
|
|
|
21
21
|
CoreStringKey["Common_Success"] = "common_success";
|
|
22
22
|
CoreStringKey["Common_Warning"] = "common_warning";
|
|
23
23
|
CoreStringKey["Common_Info"] = "common_info";
|
|
24
|
+
CoreStringKey["Common_Disposed"] = "common_disposed";
|
|
24
25
|
// Error Messages
|
|
25
26
|
CoreStringKey["Error_InvalidInput"] = "error_invalidInput";
|
|
26
27
|
CoreStringKey["Error_NetworkError"] = "error_networkError";
|
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
|
*/
|
|
@@ -33,7 +33,6 @@ class TranslatableGenericError extends Error {
|
|
|
33
33
|
this.variables = variables;
|
|
34
34
|
this.metadata = metadata;
|
|
35
35
|
// Ensure proper prototype chain for instanceof checks across transpiled targets
|
|
36
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Create error with explicit engine instance
|
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
|