@digitaldefiance/i18n-lib 1.1.5 → 1.1.6

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
@@ -564,7 +564,7 @@ I18nEngine.removeInstance('main');
564
564
 
565
565
  - `new PluginI18nEngine<TLanguages>(languages, config?)` - Create new plugin engine
566
566
  - `PluginI18nEngine.createInstance<TLanguages>(key, languages, config?)` - Create named instance
567
- - `PluginI18nEngine.getInstance<TLanguages>(key?)` - Get existing instance
567
+ - `PluginI18nEngine.getInstance<TLanguages>(key?)` - Get existing instance (throws error if not found)
568
568
 
569
569
  **Component Management**
570
570
 
@@ -762,8 +762,9 @@ describe('My tests', () => {
762
762
  #### Available Cleanup Methods
763
763
 
764
764
  - `PluginI18nEngine.clearAllInstances()` - Remove all engine instances
765
- - `PluginI18nEngine.removeInstance(key?)` - Remove specific instance by key
766
- - `PluginI18nEngine.hasInstance(key?)` - Check if instance exists
765
+ - `PluginI18nEngine.removeInstance(key?)` - Remove specific instance by key (returns boolean)
766
+ - `PluginI18nEngine.hasInstance(key?)` - Check if instance exists (returns boolean)
767
+ - `PluginI18nEngine.getInstance(key?)` - Get existing instance (throws RegistryError if not found)
767
768
  - `PluginI18nEngine.resetAll()` - Clear instances and component registrations
768
769
  - `resetAllI18nEngines()` - Convenience function that calls `resetAll()`
769
770
 
@@ -936,10 +937,18 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
936
937
 
937
938
  ## ChangeLog
938
939
 
940
+ ### Version 1.1.6
941
+
942
+ - Tue Oct 14 2025 17:04:00 GMT-0700 (Pacific Daylight Time)
943
+ - Added missing T function to i18n plugin engine
944
+
939
945
  ### Version 1.1.5
940
946
 
941
947
  - Tue Oct 14 2025 14:48:00 GMT-0700 (Pacific Daylight Time)
942
- - HotFix for GlobalActiveContext
948
+ - [Current] HotFix for GlobalActiveContext
949
+ - Fixed getInstance method to throw RegistryError when instance not found instead of auto-creating instances
950
+ - Improved test reliability and proper error handling for non-existent instances
951
+ - Updated API documentation to reflect error-throwing behavior
943
952
 
944
953
  ### Version 1.1.4
945
954
 
@@ -106,9 +106,9 @@ class ComponentRegistry {
106
106
  if (!translation) {
107
107
  throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `String key '${stringKey}' not found for component '${componentId}' in language '${actualLanguage}'`, { componentId, stringKey, language: actualLanguage });
108
108
  }
109
- // Process variables if the string is a template
109
+ // Process variables if the string key indicates it's a template
110
110
  let processedTranslation = translation;
111
- if (variables && (0, utils_1.isTemplate)(translation)) {
111
+ if (variables && (0, utils_1.isTemplate)(stringKey)) {
112
112
  processedTranslation = (0, utils_1.replaceVariables)(translation, variables);
113
113
  }
114
114
  return {
@@ -20,6 +20,10 @@ export declare class PluginI18nEngine<TLanguages extends string> {
20
20
  private readonly enumRegistry;
21
21
  private readonly config;
22
22
  private contextKey;
23
+ /**
24
+ * Default template processor instance
25
+ */
26
+ readonly t: (str: string, language?: TLanguages, ...otherVars: Record<string, string | number>[]) => string;
23
27
  /**
24
28
  * Static instances for semi-singleton pattern
25
29
  */
@@ -51,6 +51,27 @@ class PluginI18nEngine {
51
51
  globalContext.setCurrencyCode(this.config.defaultCurrencyCode, this.contextKey);
52
52
  globalContext.setUserTimezone(this.config.timezone, this.contextKey);
53
53
  globalContext.setAdminTimezone(this.config.adminTimezone, this.contextKey);
54
+ // Initialize the default template processor for component-based patterns
55
+ this.t = (str, language, ...otherVars) => {
56
+ // Step 1: Replace component-based patterns like {{componentId.stringKey}}
57
+ let result = str.replace(/\{\{([^}]+)\}\}/g, (match, pattern) => {
58
+ const parts = pattern.split('.');
59
+ if (parts.length === 2) {
60
+ const [componentId, stringKey] = parts;
61
+ // For template strings, use the first variable object if available
62
+ const isTemplate = stringKey.toLowerCase().endsWith('template');
63
+ const vars = isTemplate && otherVars.length > 0 ? otherVars[0] : {};
64
+ return this.safeTranslate(componentId.trim(), stringKey.trim(), vars, language);
65
+ }
66
+ return match; // Return original if pattern doesn't match expected format
67
+ });
68
+ // Step 2: Replace remaining variable patterns like {varName} with merged variables
69
+ const allVars = otherVars.reduce((acc, vars) => ({ ...acc, ...vars }), {});
70
+ result = result.replace(/\{(\w+)\}/g, (match, varName) => {
71
+ return allVars[varName] !== undefined ? String(allVars[varName]) : match;
72
+ });
73
+ return result;
74
+ };
54
75
  // Auto-register as default instance if none exists
55
76
  if (!PluginI18nEngine._defaultKey) {
56
77
  PluginI18nEngine._instances.set(PluginI18nEngine.DefaultInstanceKey, this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",