@digitaldefiance/i18n-lib 1.1.3 → 1.1.4

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
@@ -936,9 +936,14 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
936
936
 
937
937
  ## ChangeLog
938
938
 
939
+ ### Version 1.1.4
940
+
941
+ - Tue Oct 14 2025 14:21:00 GMT-0700 (Pacific Daylight Time)
942
+ - Removed duplicate parallel RegistryContext and focused on GlobalActiveContext
943
+
939
944
  ### Version 1.1.3
940
945
 
941
- - Tuesday Oct 14 2025 14:00:00 GMT-0700 (Pacific Daylight Time)
946
+ - Tue Oct 14 2025 14:00:00 GMT-0700 (Pacific Daylight Time)
942
947
  - Added GlobalActiveContext class instead of plain object
943
948
 
944
949
  ### Version 1.1.2
package/dist/index.d.ts CHANGED
@@ -29,7 +29,6 @@ export * from './core-string-key';
29
29
  export * from './language-registry';
30
30
  export * from './plugin-i18n-engine';
31
31
  export * from './registry-config';
32
- export * from './registry-context';
33
32
  export * from './registry-error';
34
33
  export * from './registry-error-type';
35
34
  export * from './translation-request';
package/dist/index.js CHANGED
@@ -48,7 +48,6 @@ __exportStar(require("./core-string-key"), exports);
48
48
  __exportStar(require("./language-registry"), exports);
49
49
  __exportStar(require("./plugin-i18n-engine"), exports);
50
50
  __exportStar(require("./registry-config"), exports);
51
- __exportStar(require("./registry-context"), exports);
52
51
  __exportStar(require("./registry-error"), exports);
53
52
  __exportStar(require("./registry-error-type"), exports);
54
53
  __exportStar(require("./translation-request"), exports);
@@ -5,10 +5,10 @@ import { ComponentDefinition } from './component-definition';
5
5
  import { ComponentRegistration } from './component-registration';
6
6
  import { ComponentRegistry } from './component-registry';
7
7
  import { EnumTranslationRegistry } from './enum-registry';
8
+ import { IActiveContext } from './active-context';
8
9
  import { LanguageDefinition } from './language-definition';
9
10
  import { LanguageRegistry } from './language-registry';
10
11
  import { RegistryConfig } from './registry-config';
11
- import { RegistryContext } from './registry-context';
12
12
  import { TranslationResponse } from './translation-response';
13
13
  import { EnumLanguageTranslation } from './types';
14
14
  /**
@@ -19,7 +19,7 @@ export declare class PluginI18nEngine<TLanguages extends string> {
19
19
  private readonly componentRegistry;
20
20
  private readonly enumRegistry;
21
21
  private readonly config;
22
- private context;
22
+ private contextKey;
23
23
  /**
24
24
  * Static instances for semi-singleton pattern
25
25
  */
@@ -74,11 +74,15 @@ export declare class PluginI18nEngine<TLanguages extends string> {
74
74
  /**
75
75
  * Get current context
76
76
  */
77
- getContext(): RegistryContext<TLanguages>;
77
+ getContext(): IActiveContext<TLanguages>;
78
78
  /**
79
79
  * Update context
80
80
  */
81
- updateContext(updates: Partial<RegistryContext<TLanguages>>): void;
81
+ updateContext(updates: Partial<IActiveContext<TLanguages>>): void;
82
+ /**
83
+ * Get current language from global context
84
+ */
85
+ private getCurrentLanguage;
82
86
  /**
83
87
  * Set current language
84
88
  */
@@ -7,6 +7,7 @@ exports.PluginI18nEngine = void 0;
7
7
  const component_registry_1 = require("./component-registry");
8
8
  const currency_code_1 = require("./currency-code");
9
9
  const enum_registry_1 = require("./enum-registry");
10
+ const global_active_context_1 = require("./global-active-context");
10
11
  const language_registry_1 = require("./language-registry");
11
12
  const registry_error_1 = require("./registry-error");
12
13
  const registry_error_type_1 = require("./registry-error-type");
@@ -41,14 +42,15 @@ class PluginI18nEngine {
41
42
  this.enumRegistry = new enum_registry_1.EnumTranslationRegistry(initialLanguages.map((l) => l.id), (key, vars) => this.safeTranslate('core', key, vars));
42
43
  // Register initial languages
43
44
  this.languageRegistry.registerLanguages(initialLanguages);
44
- // Initialize context
45
- this.context = {
46
- currentLanguage: this.config.defaultLanguage,
47
- fallbackLanguage: this.config.fallbackLanguage,
48
- currencyCode: this.config.defaultCurrencyCode,
49
- timezone: this.config.timezone,
50
- adminTimezone: this.config.adminTimezone,
51
- };
45
+ // Initialize context key for this engine instance
46
+ this.contextKey = PluginI18nEngine.DefaultInstanceKey;
47
+ // Create or get the global context for this engine
48
+ const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
49
+ // Always create/update the context for this engine
50
+ globalContext.createContext(this.config.defaultLanguage, this.config.defaultLanguage, this.contextKey);
51
+ globalContext.setCurrencyCode(this.config.defaultCurrencyCode, this.contextKey);
52
+ globalContext.setUserTimezone(this.config.timezone, this.contextKey);
53
+ globalContext.setAdminTimezone(this.config.adminTimezone, this.contextKey);
52
54
  // Auto-register as default instance if none exists
53
55
  if (!PluginI18nEngine._defaultKey) {
54
56
  PluginI18nEngine._instances.set(PluginI18nEngine.DefaultInstanceKey, this);
@@ -63,6 +65,13 @@ class PluginI18nEngine {
63
65
  throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.DuplicateComponent, `I18n instance with key '${key}' already exists`, { key });
64
66
  }
65
67
  const instance = new PluginI18nEngine(initialLanguages, config);
68
+ instance.contextKey = key;
69
+ // Create context for this specific instance
70
+ const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
71
+ globalContext.createContext(instance.config.defaultLanguage, instance.config.defaultLanguage, key);
72
+ globalContext.setCurrencyCode(instance.config.defaultCurrencyCode, key);
73
+ globalContext.setUserTimezone(instance.config.timezone, key);
74
+ globalContext.setAdminTimezone(instance.config.adminTimezone, key);
66
75
  PluginI18nEngine._instances.set(key, instance);
67
76
  if (!PluginI18nEngine._defaultKey) {
68
77
  PluginI18nEngine._defaultKey = key;
@@ -124,7 +133,7 @@ class PluginI18nEngine {
124
133
  const request = {
125
134
  componentId,
126
135
  stringKey,
127
- language: language || this.context.currentLanguage,
136
+ language: language || this.getCurrentLanguage(),
128
137
  variables,
129
138
  };
130
139
  const response = this.componentRegistry.getTranslation(request);
@@ -146,7 +155,7 @@ class PluginI18nEngine {
146
155
  * Translate an enum value
147
156
  */
148
157
  translateEnum(enumObj, value, language) {
149
- return this.enumRegistry.translate(enumObj, value, language || this.context.currentLanguage);
158
+ return this.enumRegistry.translate(enumObj, value, language || this.getCurrentLanguage());
150
159
  }
151
160
  /**
152
161
  * Get detailed translation response
@@ -155,7 +164,7 @@ class PluginI18nEngine {
155
164
  const request = {
156
165
  componentId,
157
166
  stringKey,
158
- language: language || this.context.currentLanguage,
167
+ language: language || this.getCurrentLanguage(),
159
168
  variables,
160
169
  };
161
170
  return this.componentRegistry.getTranslation(request);
@@ -164,13 +173,33 @@ class PluginI18nEngine {
164
173
  * Get current context
165
174
  */
166
175
  getContext() {
167
- return { ...this.context };
176
+ const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
177
+ return globalContext.getContext(this.contextKey);
168
178
  }
169
179
  /**
170
180
  * Update context
171
181
  */
172
182
  updateContext(updates) {
173
- this.context = { ...this.context, ...updates };
183
+ const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
184
+ if (updates.language)
185
+ globalContext.setUserLanguage(updates.language, this.contextKey);
186
+ if (updates.adminLanguage)
187
+ globalContext.setAdminLanguage(updates.adminLanguage, this.contextKey);
188
+ if (updates.currencyCode)
189
+ globalContext.setCurrencyCode(updates.currencyCode, this.contextKey);
190
+ if (updates.currentContext)
191
+ globalContext.setLanguageContextSpace(updates.currentContext, this.contextKey);
192
+ if (updates.timezone)
193
+ globalContext.setUserTimezone(updates.timezone, this.contextKey);
194
+ if (updates.adminTimezone)
195
+ globalContext.setAdminTimezone(updates.adminTimezone, this.contextKey);
196
+ }
197
+ /**
198
+ * Get current language from global context
199
+ */
200
+ getCurrentLanguage() {
201
+ const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
202
+ return globalContext.getContext(this.contextKey).language;
174
203
  }
175
204
  /**
176
205
  * Set current language
@@ -179,7 +208,8 @@ class PluginI18nEngine {
179
208
  if (!this.languageRegistry.hasLanguage(language)) {
180
209
  throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.LanguageNotFound, `Language '${language}' is not registered`, { language });
181
210
  }
182
- this.context.currentLanguage = language;
211
+ const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
212
+ globalContext.setUserLanguage(language, this.contextKey);
183
213
  }
184
214
  /**
185
215
  * Get available languages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",