@digitaldefiance/i18n-lib 1.3.10 → 1.3.12
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 +8 -0
- package/dist/global-active-context.d.ts +4 -0
- package/dist/global-active-context.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin-i18n-engine.js +3 -2
- package/dist/typed-error.d.ts +3 -3
- package/dist/typed-error.js +1 -1
- package/dist/typed-handleable.d.ts +4 -4
- package/dist/typed-handleable.js +3 -3
- package/dist/unified-translator.d.ts +1 -0
- package/dist/unified-translator.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2274,6 +2274,14 @@ For issues, questions, or contributions:
|
|
|
2274
2274
|
|
|
2275
2275
|
## ChangeLog
|
|
2276
2276
|
|
|
2277
|
+
### Version 1.3.12
|
|
2278
|
+
|
|
2279
|
+
- Update typed-handleable to plugin i18n
|
|
2280
|
+
|
|
2281
|
+
### Version 1.3.11
|
|
2282
|
+
|
|
2283
|
+
- Export i18nconfig
|
|
2284
|
+
|
|
2277
2285
|
### Version 1.3.10
|
|
2278
2286
|
|
|
2279
2287
|
- Add UnifiedTranslator
|
|
@@ -43,4 +43,8 @@ export declare class GlobalActiveContext<TLanguage extends string, TActiveContex
|
|
|
43
43
|
setAdminTimezone(tz: Timezone, key?: string): void;
|
|
44
44
|
get adminTimezone(): Timezone;
|
|
45
45
|
set adminTimezone(tz: Timezone);
|
|
46
|
+
/**
|
|
47
|
+
* Clear all contexts (useful for testing)
|
|
48
|
+
*/
|
|
49
|
+
static clearAll(): void;
|
|
46
50
|
}
|
|
@@ -163,6 +163,13 @@ class GlobalActiveContext {
|
|
|
163
163
|
set adminTimezone(tz) {
|
|
164
164
|
this.context.adminTimezone = tz;
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Clear all contexts (useful for testing)
|
|
168
|
+
*/
|
|
169
|
+
static clearAll() {
|
|
170
|
+
GlobalActiveContext._contextMap.clear();
|
|
171
|
+
GlobalActiveContext._instance = undefined;
|
|
172
|
+
}
|
|
166
173
|
}
|
|
167
174
|
exports.GlobalActiveContext = GlobalActiveContext;
|
|
168
175
|
GlobalActiveContext._contextMap = new Map();
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './handleable';
|
|
|
16
16
|
export * from './i-handleable';
|
|
17
17
|
export * from './i-handleable-error-options';
|
|
18
18
|
export * from './i-global-active-context';
|
|
19
|
+
export * from './i18n-config';
|
|
19
20
|
export * from './i18n-context';
|
|
20
21
|
export * from './i18n-engine';
|
|
21
22
|
export * from './language-definition';
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __exportStar(require("./handleable"), exports);
|
|
|
35
35
|
__exportStar(require("./i-handleable"), exports);
|
|
36
36
|
__exportStar(require("./i-handleable-error-options"), exports);
|
|
37
37
|
__exportStar(require("./i-global-active-context"), exports);
|
|
38
|
+
__exportStar(require("./i18n-config"), exports);
|
|
38
39
|
__exportStar(require("./i18n-context"), exports);
|
|
39
40
|
__exportStar(require("./i18n-engine"), exports);
|
|
40
41
|
__exportStar(require("./language-definition"), exports);
|
|
@@ -341,13 +341,14 @@ class PluginI18nEngine {
|
|
|
341
341
|
* Useful for test cleanup
|
|
342
342
|
*/
|
|
343
343
|
static resetAll() {
|
|
344
|
-
for
|
|
345
|
-
|
|
344
|
+
// Clear component registrations for each engine BEFORE clearing instances
|
|
345
|
+
for (const engine of PluginI18nEngine._instances.values()) {
|
|
346
346
|
engine.clearAllComponents();
|
|
347
347
|
}
|
|
348
348
|
PluginI18nEngine._instances.clear();
|
|
349
349
|
PluginI18nEngine._defaultKey = null;
|
|
350
350
|
language_registry_1.LanguageRegistry.clear();
|
|
351
|
+
global_active_context_1.GlobalActiveContext.clearAll();
|
|
351
352
|
}
|
|
352
353
|
}
|
|
353
354
|
exports.PluginI18nEngine = PluginI18nEngine;
|
package/dist/typed-error.d.ts
CHANGED
|
@@ -11,18 +11,18 @@ export type CompleteReasonMap<TEnum extends Record<string, string | number>, TSt
|
|
|
11
11
|
/**
|
|
12
12
|
* Base typed error class with common patterns
|
|
13
13
|
*/
|
|
14
|
-
export declare abstract class BaseTypedError<TEnum extends Record<string, string
|
|
14
|
+
export declare abstract class BaseTypedError<TEnum extends Record<string, string>> extends Error {
|
|
15
15
|
readonly type: TEnum[keyof TEnum];
|
|
16
16
|
readonly metadata?: Record<string, any> | undefined;
|
|
17
17
|
constructor(type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any> | undefined);
|
|
18
18
|
/**
|
|
19
19
|
* Create a simple typed error without engine dependency
|
|
20
20
|
*/
|
|
21
|
-
static createSimple<TEnum extends Record<string, string>,
|
|
21
|
+
static createSimple<TEnum extends Record<string, string>, TError extends BaseTypedError<TEnum>>(this: new (type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>) => TError, type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>): TError;
|
|
22
22
|
/**
|
|
23
23
|
* Create a typed error with translation support
|
|
24
24
|
*/
|
|
25
|
-
static createTranslated<TEnum extends Record<string, string>, TStringKey extends string, TError extends BaseTypedError<TEnum
|
|
25
|
+
static createTranslated<TEnum extends Record<string, string>, TStringKey extends string, TError extends BaseTypedError<TEnum>>(this: new (type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>) => TError, engine: TranslationEngine, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, variables?: Record<string, string | number>, language?: string, metadata?: Record<string, any>): TError;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Legacy TypedError that ensures complete enum coverage (for backward compatibility)
|
package/dist/typed-error.js
CHANGED
|
@@ -29,7 +29,7 @@ class BaseTypedError extends Error {
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a typed error with translation support
|
|
31
31
|
*/
|
|
32
|
-
static createTranslated(engine,
|
|
32
|
+
static createTranslated(engine, type, reasonMap, variables, language, metadata) {
|
|
33
33
|
const key = reasonMap[type];
|
|
34
34
|
let message;
|
|
35
35
|
if (key && engine) {
|
|
@@ -2,13 +2,13 @@ import { HandleableErrorOptions } from './i-handleable-error-options';
|
|
|
2
2
|
import { IHandleable } from './i-handleable';
|
|
3
3
|
import { HandleableError } from './handleable';
|
|
4
4
|
import { CompleteReasonMap, TranslationEngine } from './typed-error';
|
|
5
|
-
import {
|
|
6
|
-
export declare class TypedHandleableError<TEnum extends Record<string, string>, TStringKey extends string> extends HandleableError implements IHandleable {
|
|
5
|
+
import { CoreLanguageCode } from './core-i18n';
|
|
6
|
+
export declare class TypedHandleableError<TEnum extends Record<string, string>, TStringKey extends string, TLanguage extends CoreLanguageCode = CoreLanguageCode> extends HandleableError implements IHandleable {
|
|
7
7
|
readonly type: TEnum[keyof TEnum];
|
|
8
8
|
readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
|
|
9
9
|
readonly engine: TranslationEngine<TStringKey>;
|
|
10
|
-
readonly language?:
|
|
10
|
+
readonly language?: TLanguage;
|
|
11
11
|
readonly otherVars?: Record<string, string | number>;
|
|
12
|
-
constructor(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, engine: TranslationEngine<TStringKey>, language?:
|
|
12
|
+
constructor(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, engine: TranslationEngine<TStringKey>, language?: TLanguage, otherVars?: Record<string, string | number>, options?: HandleableErrorOptions);
|
|
13
13
|
toJSON(): Record<string, unknown>;
|
|
14
14
|
}
|
package/dist/typed-handleable.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedHandleableError = void 0;
|
|
4
4
|
const handleable_1 = require("./handleable");
|
|
5
|
-
const
|
|
5
|
+
const plugin_i18n_engine_1 = require("./plugin-i18n-engine");
|
|
6
6
|
const core_string_key_1 = require("./core-string-key");
|
|
7
7
|
class TypedHandleableError extends handleable_1.HandleableError {
|
|
8
8
|
constructor(type, reasonMap, engine, language, otherVars, options) {
|
|
9
9
|
const key = reasonMap[type];
|
|
10
10
|
if (!key) {
|
|
11
|
-
const coreEngine =
|
|
12
|
-
throw new Error(coreEngine.translate(core_string_key_1.CoreStringKey.Error_MissingTranslationKeyTemplate, {
|
|
11
|
+
const coreEngine = plugin_i18n_engine_1.PluginI18nEngine.getInstance();
|
|
12
|
+
throw new Error(coreEngine.translate('core', core_string_key_1.CoreStringKey.Error_MissingTranslationKeyTemplate, {
|
|
13
13
|
stringKey: key,
|
|
14
14
|
}));
|
|
15
15
|
}
|
|
@@ -26,4 +26,5 @@ export declare class UnifiedTranslator<TLanguage extends string = string> {
|
|
|
26
26
|
translate(key: string, vars?: Record<string, string | number>, language?: TLanguage): string;
|
|
27
27
|
setLanguage(language: TLanguage): void;
|
|
28
28
|
getLanguage(): TLanguage;
|
|
29
|
+
clearSources(): void;
|
|
29
30
|
}
|