@digitaldefiance/i18n-lib 1.3.7 → 1.3.8
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 +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/typed-handleable.d.ts +14 -0
- package/dist/typed-handleable.js +40 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './template';
|
|
|
23
23
|
export * from './timezone';
|
|
24
24
|
export * from './translatable-generic-error';
|
|
25
25
|
export * from './typed-error';
|
|
26
|
+
export * from './typed-handleable';
|
|
26
27
|
export * from './types';
|
|
27
28
|
export * from './utils';
|
|
28
29
|
export * from './validation-config';
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ __exportStar(require("./template"), exports);
|
|
|
42
42
|
__exportStar(require("./timezone"), exports);
|
|
43
43
|
__exportStar(require("./translatable-generic-error"), exports);
|
|
44
44
|
__exportStar(require("./typed-error"), exports);
|
|
45
|
+
__exportStar(require("./typed-handleable"), exports);
|
|
45
46
|
__exportStar(require("./types"), exports);
|
|
46
47
|
__exportStar(require("./utils"), exports);
|
|
47
48
|
__exportStar(require("./validation-config"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HandleableErrorOptions } from './i-handleable-error-options';
|
|
2
|
+
import { IHandleable } from './i-handleable';
|
|
3
|
+
import { HandleableError } from './handleable';
|
|
4
|
+
import { CompleteReasonMap, TranslationEngine } from './typed-error';
|
|
5
|
+
import { Language } from './default-config';
|
|
6
|
+
export declare class TypedHandleableError<TEnum extends Record<string, string>, TStringKey extends string> extends HandleableError implements IHandleable {
|
|
7
|
+
readonly type: TEnum[keyof TEnum];
|
|
8
|
+
readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
|
|
9
|
+
readonly engine: TranslationEngine<TStringKey>;
|
|
10
|
+
readonly language?: Language;
|
|
11
|
+
readonly otherVars?: Record<string, string | number>;
|
|
12
|
+
constructor(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, engine: TranslationEngine<TStringKey>, language?: Language, otherVars?: Record<string, string | number>, options?: HandleableErrorOptions);
|
|
13
|
+
toJSON(): Record<string, unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedHandleableError = void 0;
|
|
4
|
+
const handleable_1 = require("./handleable");
|
|
5
|
+
const i18n_engine_1 = require("./i18n-engine");
|
|
6
|
+
const core_string_key_1 = require("./core-string-key");
|
|
7
|
+
class TypedHandleableError extends handleable_1.HandleableError {
|
|
8
|
+
constructor(type, reasonMap, engine, language, otherVars, options) {
|
|
9
|
+
const key = reasonMap[type];
|
|
10
|
+
if (!key) {
|
|
11
|
+
const coreEngine = i18n_engine_1.I18nEngine.getInstance();
|
|
12
|
+
throw new Error(coreEngine.translate(core_string_key_1.CoreStringKey.Error_MissingTranslationKeyTemplate, {
|
|
13
|
+
stringKey: key,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
let message = String(type);
|
|
17
|
+
try {
|
|
18
|
+
const keyString = key;
|
|
19
|
+
const translated = engine.translate(keyString, otherVars, language);
|
|
20
|
+
message = String(translated || type);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
message = String(type);
|
|
24
|
+
}
|
|
25
|
+
super(new Error(message), options);
|
|
26
|
+
this.type = type;
|
|
27
|
+
this.reasonMap = reasonMap;
|
|
28
|
+
this.language = language;
|
|
29
|
+
this.otherVars = otherVars;
|
|
30
|
+
this.engine = engine;
|
|
31
|
+
}
|
|
32
|
+
toJSON() {
|
|
33
|
+
const baseJson = super.toJSON();
|
|
34
|
+
return {
|
|
35
|
+
...baseJson,
|
|
36
|
+
type: this.type,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.TypedHandleableError = TypedHandleableError;
|