@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 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 (const [key, engine] of PluginI18nEngine._instances) {
345
- // Clear component registrations for each engine
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;
@@ -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>, TStringKey extends string> extends Error {
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>, TStringKey extends string, TError extends BaseTypedError<TEnum, TStringKey>>(this: new (type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>) => TError, type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>): TError;
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, TStringKey>>(this: new (type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>) => TError, engine: TranslationEngine, componentId: string, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, variables?: Record<string, string | number>, language?: string, metadata?: Record<string, any>): TError;
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)
@@ -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, componentId, type, reasonMap, variables, language, metadata) {
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 { Language } from './default-config';
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?: 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?: Language, otherVars?: Record<string, string | number>, options?: HandleableErrorOptions);
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
  }
@@ -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 i18n_engine_1 = require("./i18n-engine");
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 = i18n_engine_1.I18nEngine.getInstance();
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
  }
@@ -60,5 +60,9 @@ class UnifiedTranslator {
60
60
  getLanguage() {
61
61
  return this.defaultLanguage;
62
62
  }
63
+ clearSources() {
64
+ this.sources.clear();
65
+ this.defaultSource = undefined;
66
+ }
63
67
  }
64
68
  exports.UnifiedTranslator = UnifiedTranslator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",