@digitaldefiance/i18n-lib 1.3.13 → 1.3.15
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 +143 -87
- package/package.json +4 -3
- package/src/active-context.d.ts +30 -0
- package/src/active-context.d.ts.map +1 -0
- package/src/active-context.js +3 -0
- package/src/active-context.js.map +1 -0
- package/src/component-definition.d.ts +12 -0
- package/src/component-definition.d.ts.map +1 -0
- package/src/component-definition.js +3 -0
- package/src/component-definition.js.map +1 -0
- package/src/component-registration.d.ts +10 -0
- package/src/component-registration.d.ts.map +1 -0
- package/src/component-registration.js +3 -0
- package/src/component-registration.js.map +1 -0
- package/src/component-registry.d.ts +69 -0
- package/src/component-registry.d.ts.map +1 -0
- package/src/component-registry.js +248 -0
- package/src/component-registry.js.map +1 -0
- package/src/context-error-type.d.ts +4 -0
- package/src/context-error-type.d.ts.map +1 -0
- package/src/context-error-type.js +8 -0
- package/src/context-error-type.js.map +1 -0
- package/src/context-error.d.ts +7 -0
- package/src/context-error.d.ts.map +1 -0
- package/src/context-error.js +18 -0
- package/src/context-error.js.map +1 -0
- package/src/context-manager.d.ts +34 -0
- package/src/context-manager.d.ts.map +1 -0
- package/src/context-manager.js +60 -0
- package/src/context-manager.js.map +1 -0
- package/src/context.d.ts +45 -0
- package/src/context.d.ts.map +1 -0
- package/src/context.js +70 -0
- package/src/context.js.map +1 -0
- package/src/core-i18n.d.ts +63 -0
- package/src/core-i18n.d.ts.map +1 -0
- package/src/core-i18n.js +478 -0
- package/src/core-i18n.js.map +1 -0
- package/src/core-string-key.d.ts +43 -0
- package/src/core-string-key.d.ts.map +1 -0
- package/src/core-string-key.js +51 -0
- package/src/core-string-key.js.map +1 -0
- package/src/create-translation-adapter.d.ts +21 -0
- package/src/create-translation-adapter.d.ts.map +1 -0
- package/src/create-translation-adapter.js +37 -0
- package/src/create-translation-adapter.js.map +1 -0
- package/src/currency-code.d.ts +20 -0
- package/src/currency-code.d.ts.map +1 -0
- package/src/currency-code.js +37 -0
- package/src/currency-code.js.map +1 -0
- package/src/{currency-format.ts → currency-format.d.ts} +5 -5
- package/src/currency-format.d.ts.map +1 -0
- package/src/currency-format.js +3 -0
- package/src/currency-format.js.map +1 -0
- package/src/currency.d.ts +12 -0
- package/src/currency.d.ts.map +1 -0
- package/src/currency.js +49 -0
- package/src/currency.js.map +1 -0
- package/src/default-config.d.ts +33 -0
- package/src/default-config.d.ts.map +1 -0
- package/src/default-config.js +102 -0
- package/src/default-config.js.map +1 -0
- package/src/enum-registry.d.ts +45 -0
- package/src/enum-registry.d.ts.map +1 -0
- package/src/enum-registry.js +103 -0
- package/src/enum-registry.js.map +1 -0
- package/src/global-active-context.d.ts +51 -0
- package/src/global-active-context.d.ts.map +1 -0
- package/src/global-active-context.js +179 -0
- package/src/global-active-context.js.map +1 -0
- package/src/handleable.d.ts +14 -0
- package/src/handleable.d.ts.map +1 -0
- package/src/handleable.js +66 -0
- package/src/handleable.js.map +1 -0
- package/src/i-global-active-context.d.ts +23 -0
- package/src/i-global-active-context.d.ts.map +1 -0
- package/src/i-global-active-context.js +3 -0
- package/src/i-global-active-context.js.map +1 -0
- package/src/i-handleable-error-options.d.ts +7 -0
- package/src/i-handleable-error-options.d.ts.map +1 -0
- package/src/i-handleable-error-options.js +3 -0
- package/src/i-handleable-error-options.js.map +1 -0
- package/src/i-handleable.d.ts +6 -0
- package/src/i-handleable.d.ts.map +1 -0
- package/src/i-handleable.js +3 -0
- package/src/i-handleable.js.map +1 -0
- package/src/i18n-config.d.ts +21 -0
- package/src/i18n-config.d.ts.map +1 -0
- package/src/i18n-config.js +3 -0
- package/src/i18n-config.js.map +1 -0
- package/src/{i18n-context.ts → i18n-context.d.ts} +7 -7
- package/src/i18n-context.d.ts.map +1 -0
- package/src/i18n-context.js +3 -0
- package/src/i18n-context.js.map +1 -0
- package/src/i18n-engine.d.ts +179 -0
- package/src/i18n-engine.d.ts.map +1 -0
- package/src/i18n-engine.js +355 -0
- package/src/i18n-engine.js.map +1 -0
- package/src/{index.ts → index.d.ts} +2 -10
- package/src/index.d.ts.map +1 -0
- package/src/index.js +71 -0
- package/src/index.js.map +1 -0
- package/src/{language-codes.ts → language-codes.d.ts} +12 -23
- package/src/language-codes.d.ts.map +1 -0
- package/src/language-codes.js +32 -0
- package/src/language-codes.js.map +1 -0
- package/src/language-definition.d.ts +14 -0
- package/src/language-definition.d.ts.map +1 -0
- package/src/language-definition.js +3 -0
- package/src/language-definition.js.map +1 -0
- package/src/language-registry.d.ts +114 -0
- package/src/language-registry.d.ts.map +1 -0
- package/src/language-registry.js +217 -0
- package/src/language-registry.js.map +1 -0
- package/src/plugin-i18n-engine.d.ts +151 -0
- package/src/plugin-i18n-engine.d.ts.map +1 -0
- package/src/plugin-i18n-engine.js +380 -0
- package/src/plugin-i18n-engine.js.map +1 -0
- package/src/plugin-translatable-generic-error.d.ts +30 -0
- package/src/plugin-translatable-generic-error.d.ts.map +1 -0
- package/src/plugin-translatable-generic-error.js +72 -0
- package/src/plugin-translatable-generic-error.js.map +1 -0
- package/src/plugin-translatable-handleable-generic.d.ts +29 -0
- package/src/plugin-translatable-handleable-generic.d.ts.map +1 -0
- package/src/plugin-translatable-handleable-generic.js +44 -0
- package/src/plugin-translatable-handleable-generic.js.map +1 -0
- package/src/plugin-typed-handleable.d.ts +15 -0
- package/src/plugin-typed-handleable.d.ts.map +1 -0
- package/src/plugin-typed-handleable.js +51 -0
- package/src/plugin-typed-handleable.js.map +1 -0
- package/src/registry-config.d.ts +15 -0
- package/src/registry-config.d.ts.map +1 -0
- package/src/registry-config.js +3 -0
- package/src/registry-config.js.map +1 -0
- package/src/registry-error-type.d.ts +13 -0
- package/src/registry-error-type.d.ts.map +1 -0
- package/src/registry-error-type.js +17 -0
- package/src/registry-error-type.js.map +1 -0
- package/src/registry-error.d.ts +19 -0
- package/src/registry-error.d.ts.map +1 -0
- package/src/registry-error.js +48 -0
- package/src/registry-error.js.map +1 -0
- package/src/strict-types.d.ts +19 -0
- package/src/strict-types.d.ts.map +1 -0
- package/src/strict-types.js +18 -0
- package/src/strict-types.js.map +1 -0
- package/src/template.d.ts +13 -0
- package/src/template.d.ts.map +1 -0
- package/src/template.js +31 -0
- package/src/template.js.map +1 -0
- package/src/timezone.d.ts +12 -0
- package/src/timezone.d.ts.map +1 -0
- package/src/timezone.js +24 -0
- package/src/timezone.js.map +1 -0
- package/src/translatable.d.ts +6 -0
- package/src/translatable.d.ts.map +1 -0
- package/src/translatable.js +12 -0
- package/src/translatable.js.map +1 -0
- package/src/translation-engine.d.ts +9 -0
- package/src/translation-engine.d.ts.map +1 -0
- package/src/translation-engine.js +3 -0
- package/src/translation-engine.js.map +1 -0
- package/src/translation-request.d.ts +10 -0
- package/src/translation-request.d.ts.map +1 -0
- package/src/translation-request.js +3 -0
- package/src/translation-request.js.map +1 -0
- package/src/translation-response.d.ts +9 -0
- package/src/translation-response.d.ts.map +1 -0
- package/src/translation-response.js +3 -0
- package/src/translation-response.js.map +1 -0
- package/src/typed-error.d.ts +73 -0
- package/src/typed-error.d.ts.map +1 -0
- package/src/typed-error.js +267 -0
- package/src/typed-error.js.map +1 -0
- package/src/typed-handleable.d.ts +15 -0
- package/src/typed-handleable.d.ts.map +1 -0
- package/src/typed-handleable.js +46 -0
- package/src/typed-handleable.js.map +1 -0
- package/src/{types.ts → types.d.ts} +21 -75
- package/src/types.d.ts.map +1 -0
- package/src/types.js +19 -0
- package/src/types.js.map +1 -0
- package/src/unified-translator.d.ts +31 -0
- package/src/unified-translator.d.ts.map +1 -0
- package/src/unified-translator.js +71 -0
- package/src/unified-translator.js.map +1 -0
- package/src/utils.d.ts +65 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +129 -0
- package/src/utils.js.map +1 -0
- package/src/validation-config.d.ts +12 -0
- package/src/validation-config.d.ts.map +1 -0
- package/src/validation-config.js +3 -0
- package/src/validation-config.js.map +1 -0
- package/src/validation-result.d.ts +13 -0
- package/src/validation-result.d.ts.map +1 -0
- package/src/validation-result.js +3 -0
- package/src/validation-result.js.map +1 -0
- package/LICENSE +0 -21
- package/src/active-context.ts +0 -30
- package/src/component-definition.ts +0 -11
- package/src/component-registration.ts +0 -13
- package/src/component-registry.ts +0 -392
- package/src/context-error-type.ts +0 -3
- package/src/context-error.ts +0 -16
- package/src/context-manager.ts +0 -71
- package/src/context.ts +0 -90
- package/src/core-i18n.ts +0 -609
- package/src/core-string-key.ts +0 -49
- package/src/create-translation-adapter.ts +0 -47
- package/src/currency-code.ts +0 -35
- package/src/currency.ts +0 -52
- package/src/default-config.ts +0 -199
- package/src/enum-registry.ts +0 -138
- package/src/global-active-context.ts +0 -255
- package/src/handleable.ts +0 -79
- package/src/i-global-active-context.ts +0 -59
- package/src/i-handleable-error-options.ts +0 -6
- package/src/i-handleable.ts +0 -5
- package/src/i18n-config.ts +0 -29
- package/src/i18n-engine.ts +0 -491
- package/src/language-definition.ts +0 -13
- package/src/language-registry.ts +0 -292
- package/src/plugin-i18n-engine.ts +0 -520
- package/src/plugin-translatable-generic-error.ts +0 -106
- package/src/plugin-translatable-handleable-generic.ts +0 -60
- package/src/plugin-typed-handleable.ts +0 -77
- package/src/registry-config.ts +0 -15
- package/src/registry-error-type.ts +0 -12
- package/src/registry-error.ts +0 -74
- package/src/strict-types.ts +0 -35
- package/src/template.ts +0 -63
- package/src/timezone.ts +0 -20
- package/src/translatable.ts +0 -15
- package/src/translation-engine.ts +0 -8
- package/src/translation-request.ts +0 -12
- package/src/translation-response.ts +0 -8
- package/src/typed-error.ts +0 -384
- package/src/typed-handleable.ts +0 -70
- package/src/unified-translator.ts +0 -96
- package/src/utils.ts +0 -213
- package/src/validation-config.ts +0 -11
- package/src/validation-result.ts +0 -12
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalActiveContext = void 0;
|
|
4
|
+
const context_error_1 = require("./context-error");
|
|
5
|
+
const context_error_type_1 = require("./context-error-type");
|
|
6
|
+
const currency_code_1 = require("./currency-code");
|
|
7
|
+
const timezone_1 = require("./timezone");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
class GlobalActiveContext {
|
|
10
|
+
static _contextMap = new Map();
|
|
11
|
+
static defaultContextKey = 'default';
|
|
12
|
+
static defaultLanguage = 'en-US';
|
|
13
|
+
static _instance;
|
|
14
|
+
static get instance() {
|
|
15
|
+
if (!this._instance) {
|
|
16
|
+
this._instance = new GlobalActiveContext();
|
|
17
|
+
this._instance.createContext(this.defaultLanguage);
|
|
18
|
+
}
|
|
19
|
+
return this._instance;
|
|
20
|
+
}
|
|
21
|
+
static getInstance() {
|
|
22
|
+
if (!this._instance) {
|
|
23
|
+
this._instance = new GlobalActiveContext();
|
|
24
|
+
this._instance.createContext(this.defaultLanguage);
|
|
25
|
+
}
|
|
26
|
+
return this._instance;
|
|
27
|
+
}
|
|
28
|
+
static overrideInstance(instance) {
|
|
29
|
+
this._instance = instance;
|
|
30
|
+
}
|
|
31
|
+
createContext(defaultLanguage, defaultAdminLanguage = defaultLanguage, key = GlobalActiveContext.defaultContextKey) {
|
|
32
|
+
const newContext = {
|
|
33
|
+
/**
|
|
34
|
+
* The language to use for translations in the user facing ui
|
|
35
|
+
*/
|
|
36
|
+
language: defaultLanguage,
|
|
37
|
+
/**
|
|
38
|
+
* The language to use for console/admin logs
|
|
39
|
+
*/
|
|
40
|
+
adminLanguage: defaultAdminLanguage,
|
|
41
|
+
currencyCode: new currency_code_1.CurrencyCode(types_1.DefaultCurrencyCode),
|
|
42
|
+
/**
|
|
43
|
+
* The current default context for language translations
|
|
44
|
+
*/
|
|
45
|
+
currentContext: 'user',
|
|
46
|
+
/**
|
|
47
|
+
* The timezone for the user facing UI
|
|
48
|
+
*/
|
|
49
|
+
timezone: new timezone_1.Timezone(types_1.DefaultTimezone),
|
|
50
|
+
/**
|
|
51
|
+
* The timezone for the admin console
|
|
52
|
+
*/
|
|
53
|
+
adminTimezone: new timezone_1.Timezone('UTC'),
|
|
54
|
+
};
|
|
55
|
+
GlobalActiveContext._contextMap.set(key, newContext);
|
|
56
|
+
return newContext;
|
|
57
|
+
}
|
|
58
|
+
getContext(key = GlobalActiveContext.defaultContextKey) {
|
|
59
|
+
const context = GlobalActiveContext._contextMap.get(key);
|
|
60
|
+
if (context) {
|
|
61
|
+
return context;
|
|
62
|
+
}
|
|
63
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
64
|
+
}
|
|
65
|
+
get context() {
|
|
66
|
+
return this.getContext(GlobalActiveContext.defaultContextKey);
|
|
67
|
+
}
|
|
68
|
+
set context(ctx) {
|
|
69
|
+
GlobalActiveContext._contextMap.set(GlobalActiveContext.defaultContextKey, ctx);
|
|
70
|
+
}
|
|
71
|
+
setUserLanguage(language, key = GlobalActiveContext.defaultContextKey) {
|
|
72
|
+
const context = GlobalActiveContext._contextMap.get(key);
|
|
73
|
+
if (context) {
|
|
74
|
+
context.language = language;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
78
|
+
}
|
|
79
|
+
get userLanguage() {
|
|
80
|
+
return this.context.language;
|
|
81
|
+
}
|
|
82
|
+
set userLanguage(lang) {
|
|
83
|
+
this.context.language = lang;
|
|
84
|
+
}
|
|
85
|
+
setCurrencyCode(code, key = GlobalActiveContext.defaultContextKey) {
|
|
86
|
+
const context = GlobalActiveContext._contextMap.get(key);
|
|
87
|
+
if (context) {
|
|
88
|
+
context.currencyCode = code;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
92
|
+
}
|
|
93
|
+
get currencyCode() {
|
|
94
|
+
return this.context.currencyCode;
|
|
95
|
+
}
|
|
96
|
+
set currencyCode(code) {
|
|
97
|
+
this.context.currencyCode = code;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Sets the admin language for console operations
|
|
101
|
+
* @param language The language to set for admin operations
|
|
102
|
+
*/
|
|
103
|
+
setAdminLanguage(language, key = GlobalActiveContext.defaultContextKey) {
|
|
104
|
+
const context = GlobalActiveContext._contextMap.get(key);
|
|
105
|
+
if (context) {
|
|
106
|
+
context.adminLanguage = language;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
110
|
+
}
|
|
111
|
+
get adminLanguage() {
|
|
112
|
+
return this.context.adminLanguage;
|
|
113
|
+
}
|
|
114
|
+
set adminLanguage(lang) {
|
|
115
|
+
this.context.adminLanguage = lang;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sets the language context for the current context
|
|
119
|
+
* @param context The language context to set
|
|
120
|
+
*/
|
|
121
|
+
setLanguageContextSpace(context, key = GlobalActiveContext.defaultContextKey) {
|
|
122
|
+
const ctx = GlobalActiveContext._contextMap.get(key);
|
|
123
|
+
if (ctx) {
|
|
124
|
+
ctx.currentContext = context;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
128
|
+
}
|
|
129
|
+
getLanguageContextSpace(key = GlobalActiveContext.defaultContextKey) {
|
|
130
|
+
const ctx = GlobalActiveContext._contextMap.get(key);
|
|
131
|
+
if (ctx) {
|
|
132
|
+
return ctx.currentContext;
|
|
133
|
+
}
|
|
134
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
135
|
+
}
|
|
136
|
+
get languageContextSpace() {
|
|
137
|
+
return this.context.currentContext;
|
|
138
|
+
}
|
|
139
|
+
set languageContextSpace(context) {
|
|
140
|
+
this.context.currentContext = context;
|
|
141
|
+
}
|
|
142
|
+
setUserTimezone(tz, key = GlobalActiveContext.defaultContextKey) {
|
|
143
|
+
const ctx = GlobalActiveContext._contextMap.get(key);
|
|
144
|
+
if (ctx) {
|
|
145
|
+
ctx.timezone = tz;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
149
|
+
}
|
|
150
|
+
get userTimezone() {
|
|
151
|
+
return this.context.timezone;
|
|
152
|
+
}
|
|
153
|
+
set userTimezone(tz) {
|
|
154
|
+
this.context.timezone = tz;
|
|
155
|
+
}
|
|
156
|
+
setAdminTimezone(tz, key = GlobalActiveContext.defaultContextKey) {
|
|
157
|
+
const ctx = GlobalActiveContext._contextMap.get(key);
|
|
158
|
+
if (ctx) {
|
|
159
|
+
ctx.adminTimezone = tz;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
throw new context_error_1.ContextError(context_error_type_1.ContextErrorType.InvalidContext, key);
|
|
163
|
+
}
|
|
164
|
+
get adminTimezone() {
|
|
165
|
+
return this.context.adminTimezone;
|
|
166
|
+
}
|
|
167
|
+
set adminTimezone(tz) {
|
|
168
|
+
this.context.adminTimezone = tz;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Clear all contexts (useful for testing)
|
|
172
|
+
*/
|
|
173
|
+
static clearAll() {
|
|
174
|
+
GlobalActiveContext._contextMap.clear();
|
|
175
|
+
GlobalActiveContext._instance = undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.GlobalActiveContext = GlobalActiveContext;
|
|
179
|
+
//# sourceMappingURL=global-active-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-active-context.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/global-active-context.ts"],"names":[],"mappings":";;;AACA,mDAA+C;AAC/C,6DAAwD;AACxD,mDAA+C;AAG/C,yCAAsC;AACtC,mCAIiB;AAEjB,MAAa,mBAAmB;IACpB,MAAM,CAAC,WAAW,GAAqC,IAAI,GAAG,EAAE,CAAC;IACpE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AC,CAAC;IAC/D,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;IACpC,CAAC;IAED,IAAW,aAAa,CAAC,EAAY;QACnC,IAAI,CAAC,OAAO,CAAC,aAAa,GAAG,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAAQ;QACpB,mBAAmB,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACxC,mBAAmB,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5C,CAAC;;AAhPH,kDAiPC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IHandleable } from './i-handleable';
|
|
2
|
+
import { HandleableErrorOptions } from './i-handleable-error-options';
|
|
3
|
+
export declare class HandleableError extends Error implements IHandleable {
|
|
4
|
+
readonly cause?: Error;
|
|
5
|
+
readonly statusCode: number;
|
|
6
|
+
readonly sourceData?: unknown;
|
|
7
|
+
private _handled;
|
|
8
|
+
constructor(source: Error, options?: HandleableErrorOptions);
|
|
9
|
+
get handled(): boolean;
|
|
10
|
+
set handled(value: boolean);
|
|
11
|
+
private serializeValue;
|
|
12
|
+
toJSON(): Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=handleable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleable.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/handleable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAMtE,qBAAa,eAAgB,SAAQ,KAAM,YAAW,WAAW;IAC/D,SAAyB,KAAK,CAAC,EAAE,KAAK,CAAC;IACvC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrC,OAAO,CAAC,QAAQ,CAAU;gBAEd,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAqB3D,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED,IAAW,OAAO,CAAC,KAAK,EAAE,OAAO,EAEhC;IAED,OAAO,CAAC,cAAc;IAuBf,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAazC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandleableError = void 0;
|
|
4
|
+
class HandleableError extends Error {
|
|
5
|
+
cause;
|
|
6
|
+
statusCode;
|
|
7
|
+
sourceData;
|
|
8
|
+
_handled;
|
|
9
|
+
constructor(source, options) {
|
|
10
|
+
super(source.message);
|
|
11
|
+
this.name = this.constructor.name;
|
|
12
|
+
this.cause = options?.cause ?? source;
|
|
13
|
+
this.statusCode = options?.statusCode ?? 500;
|
|
14
|
+
this._handled = options?.handled ?? false;
|
|
15
|
+
this.sourceData = options?.sourceData;
|
|
16
|
+
// Capture stack trace - prioritize source stack, then capture new one
|
|
17
|
+
if (source.stack) {
|
|
18
|
+
this.stack = source.stack;
|
|
19
|
+
}
|
|
20
|
+
else if (Error.captureStackTrace) {
|
|
21
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.stack = new Error().stack;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get handled() {
|
|
28
|
+
return this._handled;
|
|
29
|
+
}
|
|
30
|
+
set handled(value) {
|
|
31
|
+
this._handled = value;
|
|
32
|
+
}
|
|
33
|
+
serializeValue(value) {
|
|
34
|
+
if (value &&
|
|
35
|
+
typeof value === 'object' &&
|
|
36
|
+
'toJSON' in value &&
|
|
37
|
+
typeof value.toJSON === 'function') {
|
|
38
|
+
return value.toJSON();
|
|
39
|
+
}
|
|
40
|
+
if (value instanceof Error) {
|
|
41
|
+
return value.message;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
return value.map((item) => this.serializeValue(item));
|
|
45
|
+
}
|
|
46
|
+
if (value && typeof value === 'object') {
|
|
47
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.serializeValue(v)]));
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
toJSON() {
|
|
52
|
+
return {
|
|
53
|
+
name: this.name,
|
|
54
|
+
message: this.message,
|
|
55
|
+
statusCode: this.statusCode,
|
|
56
|
+
handled: this.handled,
|
|
57
|
+
stack: this.stack,
|
|
58
|
+
cause: this.serializeValue(this.cause),
|
|
59
|
+
...(this.sourceData
|
|
60
|
+
? { sourceData: this.serializeValue(this.sourceData) }
|
|
61
|
+
: {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.HandleableError = HandleableError;
|
|
66
|
+
//# sourceMappingURL=handleable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleable.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/handleable.ts"],"names":[],"mappings":";;;AAOA,MAAa,eAAgB,SAAQ,KAAK;IACf,KAAK,CAAS;IACvB,UAAU,CAAS;IACnB,UAAU,CAAW;IAC7B,QAAQ,CAAU;IAE1B,YAAY,MAAa,EAAE,OAAgC;QACzD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,MAAM,CAAC;QACtC,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,C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C,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CACnE,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC;YACtC,GAAG,CAAC,IAAI,CAAC,UAAU;gBACjB,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;gBACtD,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC;CACF;AAvED,0CAuEC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IActiveContext } from './active-context';
|
|
2
|
+
import { CurrencyCode } from './currency-code';
|
|
3
|
+
import { Timezone } from './timezone';
|
|
4
|
+
import { LanguageContextSpace } from './types';
|
|
5
|
+
export interface IGlobalActiveContext<TLanguage extends string, TActiveContext extends IActiveContext<TLanguage>> {
|
|
6
|
+
context: TActiveContext;
|
|
7
|
+
userLanguage: TLanguage;
|
|
8
|
+
currencyCode: CurrencyCode;
|
|
9
|
+
adminLanguage: TLanguage;
|
|
10
|
+
languageContextSpace: LanguageContextSpace;
|
|
11
|
+
userTimezone: Timezone;
|
|
12
|
+
adminTimezone: Timezone;
|
|
13
|
+
createContext(defaultLanguage: TLanguage, defaultAdminLanguage?: TLanguage, key?: string): TActiveContext;
|
|
14
|
+
getContext(key?: string): TActiveContext;
|
|
15
|
+
setUserLanguage(language: TLanguage, key?: string): void;
|
|
16
|
+
setCurrencyCode(code: CurrencyCode, key?: string): void;
|
|
17
|
+
setAdminLanguage(language: TLanguage, key?: string): void;
|
|
18
|
+
setLanguageContextSpace(context: LanguageContextSpace, key?: string): void;
|
|
19
|
+
getLanguageContextSpace(key?: string): LanguageContextSpace;
|
|
20
|
+
setUserTimezone(tz: Timezone, key?: string): void;
|
|
21
|
+
setAdminTimezone(tz: Timezone, key?: string): void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=i-global-active-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-global-active-context.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i-global-active-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,oBAAoB,CAAC,SAAS,SAAS,MAAM,EAAE,cAAc,SAAS,cAAc,CAAC,SAAS,CAAC;IAC9G,OAAO,EAAE,cAAc,CAAC;IACxB,YAAY,EAAE,SAAS,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,SAAS,CAAC;IACzB,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,YAAY,EAAE,QAAQ,CAAC;IACvB,aAAa,EAAE,QAAQ,CAAC;IAExB,aAAa,CACX,eAAe,EAAE,SAAS,EAC1B,oBAAoB,CAAC,EAAE,SAAS,EAChC,GAAG,CAAC,EAAE,MAAM,GACX,cAAc,CAAC;IAElB,UAAU,CACR,GAAG,CAAC,EAAE,MAAM,GACX,cAAc,CAAC;IAElB,eAAe,CACb,QAAQ,EAAE,SAAS,EACnB,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAAC;IAER,eAAe,CACb,IAAI,EAAE,YAAY,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAAC;IAER,gBAAgB,CACd,QAAQ,EAAE,SAAS,EACnB,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAAC;IAER,uBAAuB,CACrB,OAAO,EAAE,oBAAoB,EAC7B,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAAC;IAER,uBAAuB,CACrB,GAAG,CAAC,EAAE,MAAM,GACX,oBAAoB,CAAC;IAExB,eAAe,CACb,EAAE,EAAE,QAAQ,EACZ,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAAC;IAER,gBAAgB,CACd,EAAE,EAAE,QAAQ,EACZ,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAAC;CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-global-active-context.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i-global-active-context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-handleable-error-options.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i-handleable-error-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-handleable-error-options.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i-handleable-error-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-handleable.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i-handleable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,OAAO,IAAI,OAAO,CAAC;IACvB,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-handleable.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i-handleable.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CurrencyCode } from './currency-code';
|
|
2
|
+
import { Timezone } from './timezone';
|
|
3
|
+
import { LanguageCodeCollection, LanguageContextSpace, MasterStringsCollection } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* I18n configuration interface
|
|
6
|
+
*/
|
|
7
|
+
export interface I18nConfig<TStringKey extends string, TLanguage extends string, TConstants extends Record<string, any> = Record<string, any>> {
|
|
8
|
+
stringNames: TStringKey[];
|
|
9
|
+
strings: MasterStringsCollection<TStringKey, TLanguage>;
|
|
10
|
+
defaultLanguage: TLanguage;
|
|
11
|
+
defaultTranslationContext: LanguageContextSpace;
|
|
12
|
+
defaultCurrencyCode: CurrencyCode;
|
|
13
|
+
languageCodes: LanguageCodeCollection<TLanguage>;
|
|
14
|
+
languages: TLanguage[];
|
|
15
|
+
constants?: TConstants;
|
|
16
|
+
enumName?: string;
|
|
17
|
+
enumObj?: Record<string, TStringKey>;
|
|
18
|
+
timezone: Timezone;
|
|
19
|
+
adminTimezone: Timezone;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=i18n-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-config.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i18n-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,UAAU,CACzB,UAAU,SAAS,MAAM,EACzB,SAAS,SAAS,MAAM,EACxB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAE5D,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,uBAAuB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IACxD,eAAe,EAAE,SAAS,CAAC;IAC3B,yBAAyB,EAAE,oBAAoB,CAAC;IAChD,mBAAmB,EAAE,YAAY,CAAC;IAClC,aAAa,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IACjD,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACrC,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,QAAQ,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-config.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i18n-config.ts"],"names":[],"mappings":""}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { CurrencyCode } from './currency-code';
|
|
2
2
|
import { Timezone } from './timezone';
|
|
3
3
|
import { LanguageContextSpace } from './types';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* I18n context interface
|
|
7
6
|
*/
|
|
8
7
|
export interface I18nContext<TLanguage extends string> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
language: TLanguage;
|
|
9
|
+
adminLanguage: TLanguage;
|
|
10
|
+
currencyCode: CurrencyCode;
|
|
11
|
+
currentContext: LanguageContextSpace;
|
|
12
|
+
timezone: Timezone;
|
|
13
|
+
adminTimezone: Timezone;
|
|
15
14
|
}
|
|
15
|
+
//# sourceMappingURL=i18n-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-context.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i18n-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,SAAS,SAAS,MAAM;IACnD,QAAQ,EAAE,SAAS,CAAC;IACpB,aAAa,EAAE,SAAS,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,EAAE,oBAAoB,CAAC;IACrC,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,QAAQ,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-context.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i18n-context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { EnumTranslationRegistry } from './enum-registry';
|
|
2
|
+
import { I18nConfig } from './i18n-config';
|
|
3
|
+
import { I18nContext } from './i18n-context';
|
|
4
|
+
import { EnumLanguageTranslation } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Internationalization engine class
|
|
7
|
+
*/
|
|
8
|
+
export declare class I18nEngine<TStringKey extends string, TLanguage extends string, TConstants extends Record<string, any> = Record<string, any>, TContext extends I18nContext<TLanguage> = I18nContext<TLanguage>> {
|
|
9
|
+
/**
|
|
10
|
+
* Registry for enum translations
|
|
11
|
+
*/
|
|
12
|
+
protected _enumRegistry: EnumTranslationRegistry<TStringKey, TLanguage>;
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for the i18n engine
|
|
15
|
+
*/
|
|
16
|
+
readonly config: I18nConfig<TStringKey, TLanguage, TConstants>;
|
|
17
|
+
/**
|
|
18
|
+
* Static instances for semi-singleton pattern
|
|
19
|
+
*/
|
|
20
|
+
private static _instances;
|
|
21
|
+
/**
|
|
22
|
+
* Default instance key (first created instance)
|
|
23
|
+
*/
|
|
24
|
+
private static _defaultKey;
|
|
25
|
+
/**
|
|
26
|
+
* Default instance key if none is provided
|
|
27
|
+
*/
|
|
28
|
+
protected static readonly DefaultInstanceKey = "default";
|
|
29
|
+
/**
|
|
30
|
+
* Global context for translations (used if no context is provided) for this instance
|
|
31
|
+
*/
|
|
32
|
+
private _context;
|
|
33
|
+
/**
|
|
34
|
+
* Default template processor instance
|
|
35
|
+
*/
|
|
36
|
+
readonly t: (str: string, language?: TLanguage, ...otherVars: Record<string, string | number>[]) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new I18nEngine instance
|
|
39
|
+
* @param config The i18n configuration
|
|
40
|
+
* @param key Optional instance key for the semi-singleton pattern
|
|
41
|
+
* @throws Error if an instance with the same key already exists
|
|
42
|
+
*/
|
|
43
|
+
constructor(config: I18nConfig<TStringKey, TLanguage, TConstants>, key?: string, newContext?: () => TContext);
|
|
44
|
+
/**
|
|
45
|
+
* Gets an instance of the I18nEngine by key. If no key is provided, the default instance is returned.
|
|
46
|
+
* @param key The key of the instance to retrieve
|
|
47
|
+
* @returns The I18nEngine instance
|
|
48
|
+
* @throws Error if the instance with the provided key does not exist
|
|
49
|
+
*/
|
|
50
|
+
static getInstance<T extends I18nEngine<any, any, any, any>>(key?: string): T;
|
|
51
|
+
/**
|
|
52
|
+
* Gets a translation for the provided error key using the specified instance (or default instance if none is provided).
|
|
53
|
+
* @param errorKey The error key to translate
|
|
54
|
+
* @param vars Variables to replace in the translation string
|
|
55
|
+
* @param instanceKey The key of the I18nEngine instance to use
|
|
56
|
+
* @param language The language to translate to
|
|
57
|
+
* @param fallbackLanguage The fallback language if the translation is not found
|
|
58
|
+
* @returns The translated error message
|
|
59
|
+
*/
|
|
60
|
+
static getErrorMessage(errorKey: string, vars?: Record<string, string | number>, instanceKey?: string, language?: string, fallbackLanguage?: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Throws an error with a translated message using the specified instance (or default instance if none is provided).
|
|
63
|
+
* @param errorKey The error key to translate
|
|
64
|
+
* @param vars Variables to replace in the translation string
|
|
65
|
+
* @param instanceKey The key of the I18nEngine instance to use
|
|
66
|
+
* @throws Error with translated message
|
|
67
|
+
*/
|
|
68
|
+
static throwError(errorKey: string, vars?: Record<string, string | number>, instanceKey?: string): never;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the global context for translations
|
|
71
|
+
* @returns The global context object
|
|
72
|
+
*/
|
|
73
|
+
get context(): TContext;
|
|
74
|
+
/**
|
|
75
|
+
* Sets the global context for translations (used if no context is provided) for this instance
|
|
76
|
+
* @param context The context to set
|
|
77
|
+
*/
|
|
78
|
+
set context(context: Partial<TContext>);
|
|
79
|
+
/**
|
|
80
|
+
* Gets the enum translation registry for this engine instance
|
|
81
|
+
* @returns The enum translation registry
|
|
82
|
+
*/
|
|
83
|
+
get enumRegistry(): EnumTranslationRegistry<TStringKey, TLanguage>;
|
|
84
|
+
/**
|
|
85
|
+
* Translates a string key into the specified language, replacing any variables as needed.
|
|
86
|
+
* @param key The string key to translate
|
|
87
|
+
* @param vars Variables to replace in the translation string
|
|
88
|
+
* @param language The language to translate to
|
|
89
|
+
* @param fallbackLanguage The fallback language if the translation is not found
|
|
90
|
+
* @returns The translated string
|
|
91
|
+
*/
|
|
92
|
+
translate(key: TStringKey, vars?: Record<string, string | number>, language?: TLanguage, fallbackLanguage?: TLanguage): string;
|
|
93
|
+
/**
|
|
94
|
+
* Translates an enumeration value into the specified language.
|
|
95
|
+
* @param enumObj The enumeration object
|
|
96
|
+
* @param value The enumeration value to translate
|
|
97
|
+
* @param language The language to translate to
|
|
98
|
+
* @returns The translated enumeration value
|
|
99
|
+
*/
|
|
100
|
+
translateEnum<TEnum extends string | number>(enumObj: Record<string, TEnum>, value: TEnum, language: TLanguage): string;
|
|
101
|
+
/**
|
|
102
|
+
* Registers an enumeration and its translations with the engine.
|
|
103
|
+
* @param enumObj The enumeration object
|
|
104
|
+
* @param translations The translations for the enumeration
|
|
105
|
+
* @param enumName The name of the enumeration (for error messages)
|
|
106
|
+
*/
|
|
107
|
+
registerEnum<TEnum extends string | number>(enumObj: Record<string, TEnum> | Record<string | number, string | number>, translations: EnumLanguageTranslation<TEnum, TLanguage>, enumName: string): void;
|
|
108
|
+
/**
|
|
109
|
+
* Safe translation that prevents infinite recursion for error messages
|
|
110
|
+
* @param key The string key to translate
|
|
111
|
+
* @param vars Variables to replace in the translation string
|
|
112
|
+
* @param language The language to translate to
|
|
113
|
+
* @returns The translated string or the key if translation fails
|
|
114
|
+
*/
|
|
115
|
+
safeTranslate(key: TStringKey, vars?: Record<string, string | number>, language?: TLanguage): string;
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves the string for the given language and key, throwing an error if not found.
|
|
118
|
+
* @param language The language to get the string for
|
|
119
|
+
* @param key The string key to retrieve
|
|
120
|
+
* @returns The string value
|
|
121
|
+
* @throws Error if the language or string key is not found
|
|
122
|
+
*/
|
|
123
|
+
private getString;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the language code for the specified language.
|
|
126
|
+
* @param language The language to get the code for
|
|
127
|
+
* @returns The language code
|
|
128
|
+
*/
|
|
129
|
+
getLanguageCode(language: TLanguage): string;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the language for the specified language code.
|
|
132
|
+
* @param code The language code to look up
|
|
133
|
+
* @returns The language, or undefined if not found
|
|
134
|
+
*/
|
|
135
|
+
getLanguageFromCode(code: string): TLanguage | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Gets all language codes.
|
|
138
|
+
* @returns A record of all language codes
|
|
139
|
+
*/
|
|
140
|
+
getAllLanguageCodes(): Record<TLanguage, string>;
|
|
141
|
+
/**
|
|
142
|
+
* Gets all available languages.
|
|
143
|
+
* @returns An array of all available languages
|
|
144
|
+
*/
|
|
145
|
+
getAvailableLanguages(): TLanguage[];
|
|
146
|
+
/**
|
|
147
|
+
* Checks if a language is available.
|
|
148
|
+
* @param language The language to check
|
|
149
|
+
* @returns True if the language is available, false otherwise
|
|
150
|
+
*/
|
|
151
|
+
isLanguageAvailable(language: string): language is TLanguage;
|
|
152
|
+
/**
|
|
153
|
+
* Clears all instances (for testing purposes)
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
static clearInstances(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Removes a specific instance by key
|
|
159
|
+
* @param key The key of the instance to remove
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
static removeInstance(key?: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* Static error message templates for validation
|
|
165
|
+
*/
|
|
166
|
+
private static readonly ErrorTemplates;
|
|
167
|
+
/**
|
|
168
|
+
* Validates the configuration to ensure all languages have string collections
|
|
169
|
+
* and all string keys are provided for each language
|
|
170
|
+
* @param config The configuration to validate
|
|
171
|
+
* @throws Error if validation fails
|
|
172
|
+
*/
|
|
173
|
+
private validateConfig;
|
|
174
|
+
/**
|
|
175
|
+
* Gets validation error message, trying translation first, falling back to template
|
|
176
|
+
*/
|
|
177
|
+
private getValidationError;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=i18n-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-engine.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/i18n-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAwB,MAAM,SAAS,CAAC;AAGxE;;GAE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